]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge branch 'maint-0.2.7'
authorNick Mathewson <nickm@torproject.org>
Thu, 11 Feb 2016 18:04:43 +0000 (13:04 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 11 Feb 2016 18:04:43 +0000 (13:04 -0500)
1  2 
src/common/container.c

index 9f40dfa2e0c8cf249173427c2ee8ad7e9d2dfb5e,8c66bd89e4c3673c501234bf4774e76280fa6a13..2e42c9ee072f58a42d2e82bf365499dccb23b56d
@@@ -59,11 -58,16 +59,16 @@@ smartlist_clear(smartlist_t *sl
    sl->num_used = 0;
  }
  
+ #if SIZE_MAX < INT_MAX
+ #error "We don't support systems where size_t is smaller than int."
+ #endif
  /** Make sure that <b>sl</b> can hold at least <b>size</b> entries. */
 -static INLINE void
 +static inline void
- smartlist_ensure_capacity(smartlist_t *sl, int size)
+ smartlist_ensure_capacity(smartlist_t *sl, size_t size)
  {
- #if SIZEOF_SIZE_T > SIZEOF_INT
+   /* Set MAX_CAPACITY to MIN(INT_MAX, SIZE_MAX / sizeof(void*)) */
+ #if (SIZE_MAX/SIZEOF_VOID_P) > INT_MAX
  #define MAX_CAPACITY (INT_MAX)
  #else
  #define MAX_CAPACITY (int)((SIZE_MAX / (sizeof(void*))))
        while (size > higher)
          higher *= 2;
      }
 -    tor_assert(higher <= INT_MAX); /* Redundant */
 -    sl->capacity = (int) higher;
      sl->list = tor_reallocarray(sl->list, sizeof(void *),
 -                                ((size_t)sl->capacity));
 +                                ((size_t)higher));
 +    memset(sl->list + sl->capacity, 0,
 +           sizeof(void *) * (higher - sl->capacity));
-     sl->capacity = higher;
++    sl->capacity = (int) higher;
    }
  #undef ASSERT_CAPACITY
  #undef MAX_CAPACITY