summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-02-21 21:57:42 +0000
committerNick Mathewson <nickm@torproject.org>2008-02-21 21:57:42 +0000
commitb375472d14cb9165e3acab899e4388a36c03bf25 (patch)
treeae14920d819371d594d45a7020ea44a593bd44d6
parent1cd90948ab6b82f65600ed9bae45a201dfae4a3d (diff)
downloadtor-b375472d14cb9165e3acab899e4388a36c03bf25.tar.gz
tor-b375472d14cb9165e3acab899e4388a36c03bf25.zip
r14373@tombo: nickm | 2008-02-21 16:29:18 -0500
Apply warnings about implicit 64-to-32 conversions; some from Sebastian Hahn; some not. svn:r13664
-rw-r--r--src/common/crypto.c23
-rw-r--r--src/common/log.c2
-rw-r--r--src/common/util.c11
-rw-r--r--src/common/util.h2
4 files changed, 23 insertions, 15 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index a00d07465d..34d19d94ba 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -133,7 +133,7 @@ static int _crypto_global_initialized = 0;
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 @@ crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, const char *src,
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 @@ crypto_pk_public_encrypt(crypto_pk_env_t *env, char *to,
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 @@ crypto_pk_private_decrypt(crypto_pk_env_t *env, char *to,
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 @@ crypto_pk_public_checksig(crypto_pk_env_t *env, char *to,
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 @@ crypto_pk_private_sign(crypto_pk_env_t *env, char *to,
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 @@ crypto_seed_rng(void)
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
diff --git a/src/common/log.c b/src/common/log.c
index 54256bdbc6..6dfed6ca77 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -225,7 +225,7 @@ format_msg(char *buf, size_t buf_len,
/* 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);
diff --git a/src/common/util.c b/src/common/util.c
index 4cb6f1d6d2..3578dd666a 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -331,8 +331,8 @@ round_to_power_of_2(uint64_t u64)
* ===== */
/** 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 @@ tor_strstrip(char *s, const char *strip)
}
}
*s = '\0';
- return read-s;
}
/** Return a pointer to a NUL-terminated hexadecimal string encoding
@@ -1000,7 +999,8 @@ tor_timegm(struct tm *tm)
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 @@ write_all(int fd, const char *buf, size_t count, int isSocket)
{
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 @@ write_all(int fd, const char *buf, size_t count, int isSocket)
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
diff --git a/src/common/util.h b/src/common/util.h
index 307f5a97b7..f6d547cd29 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -166,7 +166,7 @@ int strcasecmpstart(const char *s1, const char *s2)
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,