[or-cvs] r13664: Apply warnings about implicit 64-to-32 conversions; some fro (in tor/trunk: . src/common)

nickm at seul.org nickm at seul.org
Thu Feb 21 21:57:42 UTC 2008


Author: nickm
Date: 2008-02-21 16:57:42 -0500 (Thu, 21 Feb 2008)
New Revision: 13664

Modified:
   tor/trunk/
   tor/trunk/src/common/crypto.c
   tor/trunk/src/common/log.c
   tor/trunk/src/common/util.c
   tor/trunk/src/common/util.h
Log:
 r14373 at tombo:  nickm | 2008-02-21 16:29:18 -0500
 Apply warnings about implicit 64-to-32 conversions; some from Sebastian Hahn; some not.



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

Modified: tor/trunk/src/common/crypto.c
===================================================================
--- tor/trunk/src/common/crypto.c	2008-02-21 21:56:04 UTC (rev 13663)
+++ tor/trunk/src/common/crypto.c	2008-02-21 21:57:42 UTC (rev 13664)
@@ -133,7 +133,7 @@
 static void
 crypto_log_errors(int severity, const char *doing)
 {
-  unsigned int err;
+  unsigned long err;
   const char *msg, *lib, *func;
   while ((err = ERR_get_error()) != 0) {
     msg = (const char*)ERR_reason_error_string(err);
@@ -518,10 +518,11 @@
 
   tor_assert(env);
   tor_assert(src);
+  tor_assert(len<INT_MAX);
 
   b = BIO_new(BIO_s_mem()); /* Create a memory BIO */
 
-  BIO_write(b, src, len);
+  BIO_write(b, src, (int)len);
 
   if (env->key)
     RSA_free(env->key);
@@ -640,8 +641,9 @@
   tor_assert(env);
   tor_assert(from);
   tor_assert(to);
+  tor_assert(fromlen<INT_MAX);
 
-  r = RSA_public_encrypt(fromlen, (unsigned char*)from, (unsigned char*)to,
+  r = RSA_public_encrypt((int)fromlen, (unsigned char*)from, (unsigned char*)to,
                          env->key, crypto_get_rsa_padding(padding));
   if (r<0) {
     crypto_log_errors(LOG_WARN, "performing RSA encryption");
@@ -665,11 +667,13 @@
   tor_assert(from);
   tor_assert(to);
   tor_assert(env->key);
+  tor_assert(fromlen<INT_MAX);
   if (!env->key->p)
     /* Not a private key */
     return -1;
 
-  r = RSA_private_decrypt(fromlen, (unsigned char*)from, (unsigned char*)to,
+  r = RSA_private_decrypt((int)fromlen,
+                          (unsigned char*)from, (unsigned char*)to,
                           env->key, crypto_get_rsa_padding(padding));
 
   if (r<0) {
@@ -693,7 +697,8 @@
   tor_assert(env);
   tor_assert(from);
   tor_assert(to);
-  r = RSA_public_decrypt(fromlen, (unsigned char*)from, (unsigned char*)to,
+  tor_assert(fromlen < INT_MAX);
+  r = RSA_public_decrypt((int)fromlen, (unsigned char*)from, (unsigned char*)to,
                          env->key, RSA_PKCS1_PADDING);
 
   if (r<0) {
@@ -754,11 +759,13 @@
   tor_assert(env);
   tor_assert(from);
   tor_assert(to);
+  tor_assert(fromlen < INT_MAX);
   if (!env->key->p)
     /* Not a private key */
     return -1;
 
-  r = RSA_private_encrypt(fromlen, (unsigned char*)from, (unsigned char*)to,
+  r = RSA_private_encrypt((int)fromlen,
+                          (unsigned char*)from, (unsigned char*)to,
                           env->key, RSA_PKCS1_PADDING);
   if (r<0) {
     crypto_log_errors(LOG_WARN, "generating RSA signature");
@@ -1672,8 +1679,8 @@
   static const char *filenames[] = {
     "/dev/srandom", "/dev/urandom", "/dev/random", NULL
   };
-  int fd;
-  int i, n;
+  int fd, i;
+  size_t n;
 #endif
 
 #if USE_RAND_POLL

Modified: tor/trunk/src/common/log.c
===================================================================
--- tor/trunk/src/common/log.c	2008-02-21 21:56:04 UTC (rev 13663)
+++ tor/trunk/src/common/log.c	2008-02-21 21:57:42 UTC (rev 13664)
@@ -225,7 +225,7 @@
     /* The message was too long; overwrite the end of the buffer with
      * "[...truncated]" */
     if (buf_len >= TRUNCATED_STR_LEN) {
-      int offset = buf_len-TRUNCATED_STR_LEN;
+      size_t offset = buf_len-TRUNCATED_STR_LEN;
       /* We have an extra 2 characters after buf_len to hold the \n\0,
        * so it's safe to add 1 to the size here. */
       strlcpy(buf+offset, TRUNCATED_STR, buf_len-offset+1);

Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c	2008-02-21 21:56:04 UTC (rev 13663)
+++ tor/trunk/src/common/util.c	2008-02-21 21:57:42 UTC (rev 13664)
@@ -331,8 +331,8 @@
  * ===== */
 
 /** Remove from the string <b>s</b> every character which appears in
- * <b>strip</b>.  Return the number of characters removed. */
-int
+ * <b>strip</b>. */
+void
 tor_strstrip(char *s, const char *strip)
 {
   char *read = s;
@@ -344,7 +344,6 @@
     }
   }
   *s = '\0';
-  return read-s;
 }
 
 /** Return a pointer to a NUL-terminated hexadecimal string encoding
@@ -1000,7 +999,8 @@
     log_warn(LD_BUG, "Out-of-range argument to tor_timegm");
     return -1;
   }
-  days = 365 * (year-1970) + n_leapdays(1970,year);
+  tor_assert(year < INT_MAX);
+  days = 365 * (year-1970) + n_leapdays(1970,(int)year);
   for (i = 0; i < tm->tm_mon; ++i)
     days += days_per_month[i];
   if (tm->tm_mon > 1 && IS_LEAPYEAR(year))
@@ -1328,6 +1328,7 @@
 {
   size_t written = 0;
   int result;
+  tor_assert(count < INT_MAX); /*XXXX021 make returnval an ssize_t */
 
   while (written != count) {
     if (isSocket)
@@ -1338,7 +1339,7 @@
       return -1;
     written += result;
   }
-  return count;
+  return (int)count;
 }
 
 /** Read from <b>fd</b> to <b>buf</b>, until we get <b>count</b> bytes

Modified: tor/trunk/src/common/util.h
===================================================================
--- tor/trunk/src/common/util.h	2008-02-21 21:56:04 UTC (rev 13663)
+++ tor/trunk/src/common/util.h	2008-02-21 21:57:42 UTC (rev 13664)
@@ -166,7 +166,7 @@
 int strcmpend(const char *s1, const char *s2) ATTR_PURE ATTR_NONNULL((1,2));
 int strcasecmpend(const char *s1, const char *s2)
   ATTR_PURE ATTR_NONNULL((1,2));
-int tor_strstrip(char *s, const char *strip) ATTR_NONNULL((1,2));
+void tor_strstrip(char *s, const char *strip) ATTR_NONNULL((1,2));
 long tor_parse_long(const char *s, int base, long min,
                     long max, int *ok, char **next);
 unsigned long tor_parse_ulong(const char *s, int base, unsigned long min,



More information about the tor-commits mailing list