[or-cvs] r8948: Try to compile with fewer warnings on irix64's MIPSpro compi (in tor/trunk: . src/common src/or)

nickm at seul.org nickm at seul.org
Tue Nov 14 01:07:57 UTC 2006


Author: nickm
Date: 2006-11-13 20:07:52 -0500 (Mon, 13 Nov 2006)
New Revision: 8948

Modified:
   tor/trunk/
   tor/trunk/src/common/compat.c
   tor/trunk/src/common/torgzip.c
   tor/trunk/src/common/torint.h
   tor/trunk/src/common/util.c
   tor/trunk/src/or/config.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/dirserv.c
   tor/trunk/src/or/eventdns.c
   tor/trunk/src/or/rendclient.c
   tor/trunk/src/or/routerparse.c
Log:
 r9313 at totoro:  nickm | 2006-11-13 20:07:41 -0500
 Try to compile with fewer warnings on irix64's MIPSpro compiler /
 environment, which apparently believes that:
   - off_t can be bigger than size_t.
   - only mean kids assign things they do not subsequently inspect.
 
 I don't try to fix the "error" that makes it say:
 
 cc-3970 cc: WARNING File = main.c, Line = 1277
   conversion from pointer to same-sized integral type (potential portability
           problem)
 
     uintptr_t sig = (uintptr_t)arg;
 
 Because really, what can you do about a compiler that claims to be c99
 but doesn't understand that void* x = NULL; uintptr_t y = (uintptr_t) x;
 is safe?
 



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r9313] on 96637b51-b116-0410-a10e-9941ebb49b64

Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/common/compat.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -135,7 +135,7 @@
     return NULL;
   }
 
-  size = filesize = lseek(fd, 0, SEEK_END);
+  size = filesize = (size_t) lseek(fd, 0, SEEK_END);
   lseek(fd, 0, SEEK_SET);
   /* ensure page alignment */
   page_size = getpagesize();

Modified: tor/trunk/src/common/torgzip.c
===================================================================
--- tor/trunk/src/common/torgzip.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/common/torgzip.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -121,7 +121,12 @@
         out_size *= 2;
         *out = tor_realloc(*out, out_size);
         stream->next_out = (unsigned char*)(*out + offset);
-        stream->avail_out = out_size - offset;
+        if (out_size - offset > UINT_MAX) {
+          log_warn(LD_BUG,  "Ran over unsigned int limit of zlib while "
+                   "uncompressing.");
+          goto err;
+        }
+        stream->avail_out = (unsigned int)(out_size - offset);
         break;
       default:
         log_warn(LD_GENERAL, "Gzip compression didn't finish: %s",
@@ -238,7 +243,12 @@
         out_size *= 2;
         *out = tor_realloc(*out, out_size);
         stream->next_out = (unsigned char*)(*out + offset);
-        stream->avail_out = out_size - offset;
+        if (out_size - offset > UINT_MAX) {
+          log_warn(LD_BUG,  "Ran over unsigned int limit of zlib while "
+                   "uncompressing.");
+          goto err;
+        }
+        stream->avail_out = (unsigned int)(out_size - offset);
         break;
       default:
         log_warn(LD_GENERAL, "Gzip decompression returned an error: %s",

Modified: tor/trunk/src/common/torint.h
===================================================================
--- tor/trunk/src/common/torint.h	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/common/torint.h	2006-11-14 01:07:52 UTC (rev 8948)
@@ -287,6 +287,16 @@
 #endif /* time_t_is_signed */
 #endif /* ifndef(TIME_MAX) */
 
+#ifndef SIZE_T_MAX
+#if (SIZEOF_SIZE_T == 4)
+#define SIZE_T_MAX 0xfffffffful
+#elif (SIZEOF_SIZE_T == 8)
+#define SIZE_T_MAX 0xfffffffffffffffful
+#else
+#error "Can't define SIZE_T_MAX"
+#endif
+#endif
+
 /* Any size_t larger than this amount is likely to be an underflow. */
 #define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1))
 

Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/common/util.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -1324,9 +1324,12 @@
     return NULL;
   }
 
-  string = tor_malloc(statbuf.st_size+1);
+  if (statbuf.st_size+1 > SIZE_T_MAX)
+    return NULL;
 
-  r = read_all(fd,string,statbuf.st_size,0);
+  string = tor_malloc((size_t)(statbuf.st_size+1));
+
+  r = read_all(fd,string,(size_t)statbuf.st_size,0);
   if (r<0) {
     log_warn(LD_FS,"Error reading from file \"%s\": %s", filename,
              strerror(errno));

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/or/config.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -3688,7 +3688,7 @@
   { "1.1a", LE_11A },
   { "1.1b", LE_11B },
   { "1.2",  LE_12 },
-  { NULL, 0 }
+  { NULL, LE_OTHER }
 };
 
 static le_version_t

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/or/control.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -1152,7 +1152,7 @@
       used_quoted_string = 1;
     }
   }
-  if (options->CookieAuthentication) {
+  if (options->CookieAuthentication && authentication_cookie_is_set) {
     if (password_len != AUTHENTICATION_COOKIE_LEN) {
       log_warn(LD_CONTROL, "Got authentication cookie with wrong length (%d)",
                (int)password_len);
@@ -1685,12 +1685,16 @@
   } else if (!strcmpstart(question, "dir/server/")) {
     size_t answer_len = 0, url_len = strlen(question)+2;
     char *url = tor_malloc(url_len);
-    int res;
     smartlist_t *descs = smartlist_create();
     const char *msg;
+    int res;
     char *cp;
     tor_snprintf(url, url_len, "/tor/%s", question+4);
     res = dirserv_get_routerdescs(descs, url, &msg);
+    if (res) {
+      log_warn(LD_CONTROL, "getinfo '%s': %s", question, msg);
+      return -1;
+    }
     SMARTLIST_FOREACH(descs, signed_descriptor_t *, sd,
                       answer_len += sd->signed_descriptor_len);
     cp = *answer = tor_malloc(answer_len+1);

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/or/dirserv.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -1953,7 +1953,8 @@
 static int
 connection_dirserv_add_dir_bytes_to_outbuf(dir_connection_t *conn)
 {
-  int bytes, remaining;
+  ssize_t bytes;
+  int64_t remaining;
 
   bytes = DIRSERV_BUFFER_MIN - buf_datalen(conn->_base.outbuf);
   tor_assert(bytes > 0);
@@ -1962,7 +1963,7 @@
     bytes = 8192;
   remaining = conn->cached_dir->dir_z_len - conn->cached_dir_offset;
   if (bytes > remaining)
-    bytes = remaining;
+    bytes = (ssize_t) remaining;
 
   if (conn->zlib_state) {
     connection_write_to_buf_zlib(conn,

Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/or/eventdns.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -887,6 +887,8 @@
 	GET16(answers);
 	GET16(authority);
 	GET16(additional);
+	(void) authority;
+	(void) additional;
 
 	req = request_find_from_trans_id(trans_id);
 	if (!req) return -1;
@@ -1224,7 +1226,7 @@
 	APPEND16(class);
 #undef APPEND16
 
-	return j;
+	return (int)j;
 }
 
 // this is a libevent callback function which is called when a request
@@ -1792,6 +1794,7 @@
 
 	// we ran off the end of the list and still didn't find the requested string
 	abort();
+	return NULL; /* unreachable. */
 }
 
 static int
@@ -2005,10 +2008,12 @@
 	}
 	if (st.st_size > 65535) { err = 3; goto out1; }	 // no resolv.conf should be any bigger
 
-	resolv = (u8 *) malloc(st.st_size + 1);
+	resolv = (u8 *) malloc((size_t)st.st_size + 1);
 	if (!resolv) { err = 4; goto out1; }
 
-	if (read(fd, resolv, st.st_size) != st.st_size) { err = 5; goto out2; }
+	if (read(fd, resolv, (size_t)st.st_size) != st.st_size) {
+		err = 5; goto out2;
+	}
 	resolv[st.st_size] = 0;	 // we malloced an extra byte
 
 	start = (char *) resolv;

Modified: tor/trunk/src/or/rendclient.c
===================================================================
--- tor/trunk/src/or/rendclient.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/or/rendclient.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -134,7 +134,7 @@
    * to avoid buffer overflows? */
   r = crypto_pk_public_hybrid_encrypt(entry->parsed->pk, payload+DIGEST_LEN,
                                       tmp,
-                                      dh_offset+DH_KEY_LEN,
+                                      (int)(dh_offset+DH_KEY_LEN),
                                       PK_PKCS1_OAEP_PADDING, 0);
   if (r<0) {
     log_warn(LD_BUG,"Internal error: hybrid pk encrypt failed.");

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2006-11-14 00:06:45 UTC (rev 8947)
+++ tor/trunk/src/or/routerparse.c	2006-11-14 01:07:52 UTC (rev 8948)
@@ -147,7 +147,7 @@
   { "client-versions",     K_CLIENT_VERSIONS,     ARGS,    NO_OBJ, NETSTATUS },
   { "server-versions",     K_SERVER_VERSIONS,     ARGS,    NO_OBJ, NETSTATUS },
   { "eventdns",            K_EVENTDNS,            ARGS,    NO_OBJ, RTR },
-  { NULL, -1, NO_ARGS, NO_OBJ, ANY }
+  { NULL, _NIL, NO_ARGS, NO_OBJ, ANY }
 };
 
 /* static function prototypes */



More information about the tor-commits mailing list