[or-cvs] Fix some more obscure compiler warnings

Nick Mathewson nickm at seul.org
Mon Mar 14 03:28:48 UTC 2005


Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv8831/src/common

Modified Files:
	compat.c compat.h 
Log Message:
Fix some more obscure compiler warnings

Index: compat.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- compat.c	14 Mar 2005 03:18:34 -0000	1.42
+++ compat.c	14 Mar 2005 03:28:46 -0000	1.43
@@ -362,7 +362,8 @@
 /** Get the maximum allowed number of file descriptors. (Some systems
  * have a low soft limit.) Make sure we set it to at least
  * <b>*limit</b>. Return a new limit if we can, or -1 if we fail. */
-int set_max_file_descriptors(int limit, int cap) {
+int
+set_max_file_descriptors(unsigned long limit, unsigned long cap) {
 #ifndef HAVE_GETRLIMIT
   log_fn(LOG_INFO,"This platform is missing getrlimit(). Proceeding.");
   if (limit > cap) {
@@ -371,7 +372,9 @@
   }
 #else
   struct rlimit rlim;
-  int most;
+  unsigned long most;
+  tor_assert(limit > 0);
+  tor_assert(cap > 0);
 
   if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
     log_fn(LOG_WARN, "Could not get maximum number of file descriptors: %s",
@@ -379,13 +382,13 @@
     return -1;
   }
   if (rlim.rlim_max < limit) {
-    log_fn(LOG_WARN,"We need %d file descriptors available, and we're limited to %lu. Please change your ulimit -n.", limit, (unsigned long int)rlim.rlim_max);
+    log_fn(LOG_WARN,"We need %lu file descriptors available, and we're limited to %lu. Please change your ulimit -n.", limit, (unsigned long)rlim.rlim_max);
     return -1;
   }
-  most = ((rlim.rlim_max > cap) ? cap : rlim.rlim_max);
+  most = (rlim.rlim_max > cap) ? cap : (unsigned) rlim.rlim_max;
   if (most > rlim.rlim_cur) {
-    log_fn(LOG_INFO,"Raising max file descriptors from %lu to %d.",
-           (unsigned long int)rlim.rlim_cur, most);
+    log_fn(LOG_INFO,"Raising max file descriptors from %lu to %lu.",
+           (unsigned long)rlim.rlim_cur, most);
   }
   rlim.rlim_cur = most;
   if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {

Index: compat.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- compat.h	14 Mar 2005 03:18:34 -0000	1.25
+++ compat.h	14 Mar 2005 03:28:46 -0000	1.26
@@ -197,7 +197,7 @@
 void set_uint32(char *cp, uint32_t v);
 #endif
 
-int set_max_file_descriptors(int limit, int cap);
+int set_max_file_descriptors(unsigned long limit, unsigned long cap);
 int switch_id(char *user, char *group);
 #ifdef HAVE_PWD_H
 char *get_user_homedir(const char *username);



More information about the tor-commits mailing list