[tor-commits] [tor/master] Merge branch 'maint-0.2.7'
nickm at torproject.org
nickm at torproject.org
Thu Feb 11 18:05:25 UTC 2016
commit 7788ee43e519a8f39e3917c4161e7c635cd2ecd9
Merge: 838d4de be6174f
Author: Nick Mathewson <nickm at torproject.org>
Date: Thu Feb 11 13:04:43 2016 -0500
Merge branch 'maint-0.2.7'
changes/bug18162 | 7 +++++++
src/common/container.c | 36 +++++++++++++++++++-----------------
2 files changed, 26 insertions(+), 17 deletions(-)
diff --cc src/common/container.c
index 9f40dfa,8c66bd8..2e42c9e
--- 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 <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*))))
@@@ -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
More information about the tor-commits
mailing list