mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-14 22:51:50 +03:00
add a size check when declare a stack array to be less than 2048 bytes
This commit is contained in:
parent
8dc97b1108
commit
48f66cf4a2
4 changed files with 11 additions and 7 deletions
|
|
@ -135,10 +135,14 @@ typedef enum malloc_init_e malloc_init_t;
|
|||
# include <stdlib.h>
|
||||
# endif
|
||||
# endif
|
||||
# define VARIABLE_ARRAY(type, name, count) \
|
||||
# define VARIABLE_ARRAY_UNSAFE(type, name, count) \
|
||||
type *name = alloca(sizeof(type) * (count))
|
||||
#else
|
||||
# define VARIABLE_ARRAY(type, name, count) type name[(count)]
|
||||
# define VARIABLE_ARRAY_UNSAFE(type, name, count) type name[(count)]
|
||||
#endif
|
||||
#define VARIABLE_ARRAY_SIZE_MAX 2048
|
||||
#define VARIABLE_ARRAY(type, name, count) \
|
||||
assert(sizeof(type) * (count) <= VARIABLE_ARRAY_SIZE_MAX); \
|
||||
VARIABLE_ARRAY_UNSAFE(type, name, count)
|
||||
|
||||
#endif /* JEMALLOC_INTERNAL_TYPES_H */
|
||||
|
|
|
|||
|
|
@ -1379,7 +1379,7 @@ ctl_refresh(tsdn_t *tsdn) {
|
|||
const unsigned narenas = ctl_arenas->narenas;
|
||||
assert(narenas > 0);
|
||||
ctl_arena_t *ctl_sarena = arenas_i(MALLCTL_ARENAS_ALL);
|
||||
VARIABLE_ARRAY(arena_t *, tarenas, narenas);
|
||||
VARIABLE_ARRAY_UNSAFE(arena_t *, tarenas, narenas);
|
||||
|
||||
/*
|
||||
* Clear sum stats, since they will be merged into by
|
||||
|
|
@ -2726,7 +2726,7 @@ arena_i_decay(tsdn_t *tsdn, unsigned arena_ind, bool all) {
|
|||
*/
|
||||
if (arena_ind == MALLCTL_ARENAS_ALL || arena_ind == narenas) {
|
||||
unsigned i;
|
||||
VARIABLE_ARRAY(arena_t *, tarenas, narenas);
|
||||
VARIABLE_ARRAY_UNSAFE(arena_t *, tarenas, narenas);
|
||||
|
||||
for (i = 0; i < narenas; i++) {
|
||||
tarenas[i] = arena_get(tsdn, i, false);
|
||||
|
|
|
|||
|
|
@ -1896,7 +1896,7 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
|
|||
size_t mib[3];
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
size_t sz;
|
||||
VARIABLE_ARRAY(bool, initialized, narenas);
|
||||
VARIABLE_ARRAY_UNSAFE(bool, initialized, narenas);
|
||||
bool destroyed_initialized;
|
||||
unsigned i, ninitialized;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ static void
|
|||
hash_variant_verify_key(hash_variant_t variant, uint8_t *key) {
|
||||
const int hashbytes = hash_variant_bits(variant) / 8;
|
||||
const int hashes_size = hashbytes * 256;
|
||||
VARIABLE_ARRAY(uint8_t, hashes, hashes_size);
|
||||
VARIABLE_ARRAY(uint8_t, final, hashbytes);
|
||||
VARIABLE_ARRAY_UNSAFE(uint8_t, hashes, hashes_size);
|
||||
VARIABLE_ARRAY_UNSAFE(uint8_t, final, hashbytes);
|
||||
unsigned i;
|
||||
uint32_t computed, expected;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue