diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-02-11 12:54:52 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-02-11 12:54:52 -0500 |
commit | c2fd64846978290b0e7c7165d7658a5e704eee8f (patch) | |
tree | 35fafcafc8652e55b0734b19b3d77cc3e3816d47 /src/common/container.c | |
parent | bca7083e8285e8e6a4377076a7e432417eafc6d2 (diff) | |
download | tor-c2fd64846978290b0e7c7165d7658a5e704eee8f.tar.gz tor-c2fd64846978290b0e7c7165d7658a5e704eee8f.zip |
Make ensure_capacity a bit more pedantically correct
Issues noted by cypherpunks on #18162
Diffstat (limited to 'src/common/container.c')
-rw-r--r-- | src/common/container.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/common/container.c b/src/common/container.c index 46d9c2ee79..b1431dfa90 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -58,11 +58,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 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*)))) |