add a size check when declare a stack array to be less than 2048 bytes

This commit is contained in:
Shirui Cheng 2024-07-18 15:36:08 -07:00 committed by Qi Wang
parent 8dc97b1108
commit 48f66cf4a2
4 changed files with 11 additions and 7 deletions

View file

@ -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 */