[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r13662: Fix all -Wshorten-64-to-32 warnings that appear on my macboo (in tor/trunk: . src/common src/or)



Author: nickm
Date: 2008-02-21 16:15:31 -0500 (Thu, 21 Feb 2008)
New Revision: 13662

Modified:
   tor/trunk/
   tor/trunk/src/common/compat.c
   tor/trunk/src/common/compat.h
   tor/trunk/src/or/buffers.c
   tor/trunk/src/or/eventdns.c
   tor/trunk/src/or/rephist.c
Log:
 r14371@tombo:  nickm | 2008-02-21 16:13:18 -0500
 Fix all -Wshorten-64-to-32 warnings that appear on my macbook.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14371] on 49666b30-7950-49c5-bedf-9dc8f3168102

Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c	2008-02-21 20:54:45 UTC (rev 13661)
+++ tor/trunk/src/common/compat.c	2008-02-21 21:15:31 UTC (rev 13662)
@@ -754,10 +754,6 @@
 
 #define ULIMIT_BUFFER 32 /* keep 32 extra fd's beyond _ConnLimit */
 
-#if defined(HAVE_GETRLIMIT) && !defined(HAVE_RLIM_T)
-typedef unsigned long rlim_t;
-#endif
-
 /** Learn the maximum allowed number of file descriptors. (Some systems
  * have a low soft limit.
  *
@@ -767,7 +763,7 @@
  *
  * Otherwise, return 0 and store the maximum we found inside <b>max_out</b>.*/
 int
-set_max_file_descriptors(unsigned long limit, int *max_out)
+set_max_file_descriptors(rlim_t limit, int *max_out)
 {
 #define DEFAULT_MAX_CONNECTIONS 15000
 #define CYGWIN_MAX_CONNECTIONS 3200
@@ -819,10 +815,10 @@
     return -1;
   }
 
-  if ((unsigned long)rlim.rlim_max < limit) {
+  if (rlim.rlim_max < limit) {
     log_warn(LD_CONFIG,"We need %lu file descriptors available, and we're "
              "limited to %lu. Please change your ulimit -n.",
-             limit, (unsigned long)rlim.rlim_max);
+             (unsigned long)limit, (unsigned long)rlim.rlim_max);
     return -1;
   }
 
@@ -843,7 +839,7 @@
         if (rlim.rlim_cur < (rlim_t)limit) {
           log_warn(LD_CONFIG, "We are limited to %lu file descriptors by "
                  "OPEN_MAX, and ConnLimit is %lu.  Changing ConnLimit; sorry.",
-                   (unsigned long)OPEN_MAX, limit);
+                   (unsigned long)OPEN_MAX, (unsigned long)limit);
         } else {
           log_info(LD_CONFIG, "Dropped connection limit to OPEN_MAX (%lu); "
                    "Apparently, %lu was too high and rlimit lied to us.",
@@ -869,7 +865,7 @@
     return -1;
   }
   if (limit > INT_MAX)
-          limit = INT_MAX;
+    limit = INT_MAX;
   tor_assert(max_out);
   *max_out = (int)limit - ULIMIT_BUFFER;
   return 0;

Modified: tor/trunk/src/common/compat.h
===================================================================
--- tor/trunk/src/common/compat.h	2008-02-21 20:54:45 UTC (rev 13661)
+++ tor/trunk/src/common/compat.h	2008-02-21 21:15:31 UTC (rev 13662)
@@ -37,9 +37,15 @@
 #include <ctype.h>
 #endif
 #include <stdarg.h>
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
@@ -443,7 +449,10 @@
 void set_uint16(char *cp, uint16_t v) ATTR_NONNULL((1));
 void set_uint32(char *cp, uint32_t v) ATTR_NONNULL((1));
 
-int set_max_file_descriptors(unsigned long limit, int *max);
+#if !defined(HAVE_RLIM_T)
+typedef unsigned long rlim_t;
+#endif
+int set_max_file_descriptors(rlim_t limit, int *max);
 int switch_id(const char *user, const char *group);
 #ifdef HAVE_PWD_H
 char *get_user_homedir(const char *username);

Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c	2008-02-21 20:54:45 UTC (rev 13661)
+++ tor/trunk/src/or/buffers.c	2008-02-21 21:15:31 UTC (rev 13662)
@@ -998,7 +998,7 @@
 /** Internal structure: represents a position in a buffer. */
 typedef struct buf_pos_t {
   const chunk_t *chunk; /**< Which chunk are we pointing to? */
-  off_t pos;/**< Which character inside the chunk's data are we pointing to? */
+  int pos;/**< Which character inside the chunk's data are we pointing to? */
   size_t chunk_pos; /**< Total length of all previous chunks. */
 } buf_pos_t;
 
@@ -1037,7 +1037,7 @@
   }
   pos = out->pos;
   for (chunk = out->chunk; chunk; chunk = chunk->next) {
-    char *cp = memchr(chunk->data+pos, ch, chunk->datalen-pos);
+    char *cp = memchr(chunk->data+pos, ch, chunk->datalen - pos);
     if (cp) {
       out->chunk = chunk;
       out->pos = cp - chunk->data;

Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c	2008-02-21 20:54:45 UTC (rev 13661)
+++ tor/trunk/src/or/eventdns.c	2008-02-21 21:15:31 UTC (rev 13662)
@@ -1298,8 +1298,12 @@
 {
 	int i;
 	for (i = 0; i < table->n_labels; ++i) {
-		if (!strcmp(label, table->labels[i].v))
-			return table->labels[i].pos;
+		if (!strcmp(label, table->labels[i].v)) {
+			off_t pos = table->labels[i].pos;
+            if (pos > 65535)
+                return -1;
+            return (int)pos;
+        }
 	}
 	return -1;
 }
@@ -1682,7 +1686,7 @@
 		buf[3] |= 0x02; /* set the truncated bit. */
 	}
 
-	req->response_len = j;
+	req->response_len = (size_t)j;
 
 	if (!(req->response = malloc(req->response_len))) {
 		server_request_free_answers(req);

Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c	2008-02-21 20:54:45 UTC (rev 13661)
+++ tor/trunk/src/or/rephist.c	2008-02-21 21:15:31 UTC (rev 13662)
@@ -361,8 +361,9 @@
       (unsigned long)(hist->weighted_run_length * alpha);
     hist->total_run_weights *= alpha;
 
-    hist->weighted_uptime *= alpha;
-    hist->total_weighted_time *= alpha;
+    hist->weighted_uptime = (unsigned long)(hist->weighted_uptime * alpha);
+    hist->total_weighted_time = (unsigned long)
+      (hist->total_weighted_time * alpha);
   }
 
   return stability_last_downrated + STABILITY_INTERVAL;