mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-13 13:11:25 +00:00
Limit the minimal size of bh_hashmap (#2073)
Limit the minimal size of bh_hashmap to avoid creating hashmap with size 0, and `divide by zero` when calling bh_hash_map_find. Reported by #2008.
This commit is contained in:
parent
0a7994ac0a
commit
8ee8ab3099
|
@ -33,6 +33,9 @@ bh_hash_map_create(uint32 size, bool use_lock, HashFunc hash_func,
|
||||||
HashMap *map;
|
HashMap *map;
|
||||||
uint64 total_size;
|
uint64 total_size;
|
||||||
|
|
||||||
|
if (size < HASH_MAP_MIN_SIZE)
|
||||||
|
size = HASH_MAP_MIN_SIZE;
|
||||||
|
|
||||||
if (size > HASH_MAP_MAX_SIZE) {
|
if (size > HASH_MAP_MAX_SIZE) {
|
||||||
LOG_ERROR("HashMap create failed: size is too large.\n");
|
LOG_ERROR("HashMap create failed: size is too large.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Minimum initial size of hash map */
|
||||||
|
#define HASH_MAP_MIN_SIZE 4
|
||||||
|
|
||||||
/* Maximum initial size of hash map */
|
/* Maximum initial size of hash map */
|
||||||
#define HASH_MAP_MAX_SIZE 65536
|
#define HASH_MAP_MAX_SIZE 65536
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user