commit 39bbb8d9cfb0258b1e65dc98177e0773a19e4eb0 Author: rl1987 rl1987@sdf.lonestar.org Date: Mon Jun 4 11:56:37 2018 +0300
Avoid casting smartlist index implicitly --- changes/bug26282 | 4 ++++ src/common/util.c | 4 ++-- src/or/control.c | 2 +- src/or/geoip.c | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/changes/bug26282 b/changes/bug26282 new file mode 100644 index 000000000..c278f0b60 --- /dev/null +++ b/changes/bug26282 @@ -0,0 +1,4 @@ + o Minor bugfixes (C correctness): + - Avoid casting smartlist index to int implicitly, as it may trigger + a warning (-Wshorten-64-to-32). Fixes bug 26282; bugfix on + 0.2.3.13-alpha, 0.2.7.1-alpha and 0.2.1.1-alpha. diff --git a/src/common/util.c b/src/common/util.c index 53e4507f1..b0eb96306 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -4813,7 +4813,7 @@ process_environment_make(struct smartlist_t *env_vars)
total_env_length = 1; /* terminating NUL of terminating empty string */ for (i = 0; i < n_env_vars; ++i) { - const char *s = smartlist_get(env_vars, i); + const char *s = smartlist_get(env_vars, (int)i); size_t slen = strlen(s);
tor_assert(slen + 1 != 0); @@ -4843,7 +4843,7 @@ process_environment_make(struct smartlist_t *env_vars) const char *prev_env_var = NULL;
for (i = 0; i < n_env_vars; ++i) { - const char *s = smartlist_get(env_vars_sorted, i); + const char *s = smartlist_get(env_vars_sorted, (int)i); size_t slen = strlen(s); size_t s_name_len = str_num_before(s, '=');
diff --git a/src/or/control.c b/src/or/control.c index 0d637dce7..95b16cf5a 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -4624,7 +4624,7 @@ handle_control_add_onion(control_connection_t *conn, static const char *max_s_prefix = "MaxStreams="; static const char *auth_prefix = "ClientAuth=";
- const char *arg = smartlist_get(args, i); + const char *arg = smartlist_get(args, (int)i); if (!strcasecmpstart(arg, port_prefix)) { /* "Port=VIRTPORT[,TARGET]". */ const char *port_str = arg + strlen(port_prefix); diff --git a/src/or/geoip.c b/src/or/geoip.c index 2c917c564..d59043a7f 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -150,7 +150,7 @@ geoip_add_entry(const tor_addr_t *low, const tor_addr_t *high, idx = ((uintptr_t)idxplus1_)-1; } { - geoip_country_t *c = smartlist_get(geoip_countries, idx); + geoip_country_t *c = smartlist_get(geoip_countries, (int)idx); tor_assert(!strcasecmp(c->countrycode, country)); }