From: Nick Mathewson Date: Thu, 11 Feb 2016 18:04:43 +0000 (-0500) Subject: Merge branch 'maint-0.2.7' X-Git-Tag: tor-0.2.8.2-alpha~123 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7788ee43e519a8f39e3917c4161e7c635cd2ecd9;p=thirdparty%2Ftor.git Merge branch 'maint-0.2.7' --- 7788ee43e519a8f39e3917c4161e7c635cd2ecd9 diff --cc src/common/container.c index 9f40dfa2e0,8c66bd89e4..2e42c9ee07 --- a/src/common/container.c +++ b/src/common/container.c @@@ -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 sl can hold at least size 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*)))) @@@ -83,11 -83,10 +84,11 @@@ 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