]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge branch 'maint-0.2.5' into maint-0.2.6
authorNick Mathewson <nickm@torproject.org>
Thu, 11 Feb 2016 17:57:28 +0000 (12:57 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 11 Feb 2016 18:00:25 +0000 (13:00 -0500)
1  2 
src/common/container.c

index 864fd8a552b55f8111d14e1075804a5379aff8f6,c668068e9e5d35b5e9dda8b3de7f157ee04fd319..76c129df0bac693218d3d49d549cd6926edc4a23
@@@ -66,28 -71,22 +71,25 @@@ smartlist_ensure_capacity(smartlist_t *
  #define MAX_CAPACITY (INT_MAX)
  #else
  #define MAX_CAPACITY (int)((SIZE_MAX / (sizeof(void*))))
- #define ASSERT_CAPACITY
  #endif
-   if (size > sl->capacity) {
-     int higher = sl->capacity;
++
+   tor_assert(size <= MAX_CAPACITY);
+   if (size > (size_t) sl->capacity) {
+     size_t higher = (size_t) sl->capacity;
      if (PREDICT_UNLIKELY(size > MAX_CAPACITY/2)) {
- #ifdef ASSERT_CAPACITY
-       /* We don't include this assertion when MAX_CAPACITY == INT_MAX,
-        * since int size; (size <= INT_MAX) makes analysis tools think we're
-        * doing something stupid. */
--      tor_assert(size <= MAX_CAPACITY);
- #endif
        higher = MAX_CAPACITY;
      } else {
        while (size > higher)
          higher *= 2;
      }
-     sl->capacity = higher;
+     tor_assert(higher <= INT_MAX); /* Redundant */
+     sl->capacity = (int) higher;
 -    sl->list = tor_realloc(sl->list, sizeof(void*)*((size_t)sl->capacity));
 +    sl->list = tor_reallocarray(sl->list, sizeof(void *),
 +                                ((size_t)sl->capacity));
    }
 +#undef ASSERT_CAPACITY
 +#undef MAX_CAPACITY
  }
  
  /** Append element to the end of the list. */