diff options
author | Jason Evans <jasone@canonware.com> | 2016-02-21 07:41:33 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2016-02-21 07:41:33 (GMT) |
commit | ecae12323d44cd739662051a2b9a5965cbe0e965 (patch) | |
tree | 5ac2ad9192b0a37136d0e58474ddc488935c610a /include/jemalloc/internal/util.h | |
parent | aac93f414eaeea8b84e14bd9b6a2430828ba700d (diff) | |
download | jemalloc-ecae12323d44cd739662051a2b9a5965cbe0e965.zip jemalloc-ecae12323d44cd739662051a2b9a5965cbe0e965.tar.gz jemalloc-ecae12323d44cd739662051a2b9a5965cbe0e965.tar.bz2 |
Fix overflow in prng_range().
Add jemalloc_ffs64() and use it instead of jemalloc_ffsl() in
prng_range(), since long is not guaranteed to be a 64-bit type.
Diffstat (limited to 'include/jemalloc/internal/util.h')
-rw-r--r-- | include/jemalloc/internal/util.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/include/jemalloc/internal/util.h b/include/jemalloc/internal/util.h index dfe5c93..39f7087 100644 --- a/include/jemalloc/internal/util.h +++ b/include/jemalloc/internal/util.h @@ -121,6 +121,7 @@ void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2); #ifdef JEMALLOC_H_INLINES #ifndef JEMALLOC_ENABLE_INLINE +int jemalloc_ffs64(uint64_t bitmap); int jemalloc_ffsl(long bitmap); int jemalloc_ffs(int bitmap); uint64_t pow2_ceil_u64(uint64_t x); @@ -134,11 +135,25 @@ int get_errno(void); #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_UTIL_C_)) /* Sanity check. */ -#if !defined(JEMALLOC_INTERNAL_FFSL) || !defined(JEMALLOC_INTERNAL_FFS) -# error Both JEMALLOC_INTERNAL_FFSL && JEMALLOC_INTERNAL_FFS should have been defined by configure +#if !defined(JEMALLOC_INTERNAL_FFSLL) || !defined(JEMALLOC_INTERNAL_FFSL) \ + || !defined(JEMALLOC_INTERNAL_FFS) +# error JEMALLOC_INTERNAL_FFS{,L,LL} should have been defined by configure #endif JEMALLOC_ALWAYS_INLINE int +jemalloc_ffs64(uint64_t bitmap) +{ + +#if LG_SIZEOF_LONG == 3 + return (JEMALLOC_INTERNAL_FFSL(bitmap)); +#elif LG_SIZEOF_LONG_LONG == 3 + return (JEMALLOC_INTERNAL_FFSLL(bitmap)); +#else +#error No implementation for 64-bit ffs() +#endif +} + +JEMALLOC_ALWAYS_INLINE int jemalloc_ffsl(long bitmap) { |