Browse Source

Avoid casting smartlist index implicitly

rl1987 5 years ago
parent
commit
39bbb8d9cf
4 changed files with 8 additions and 4 deletions
  1. 4 0
      changes/bug26282
  2. 2 2
      src/common/util.c
  3. 1 1
      src/or/control.c
  4. 1 1
      src/or/geoip.c

+ 4 - 0
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.

+ 2 - 2
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, '=');
 

+ 1 - 1
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);

+ 1 - 1
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));
   }