mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-06-18 02:59:21 +00:00
Fix wasm loader malloc(0) issue which returns NULL is some platforms (#397)
Signed-off-by: Huang Qi <huangqi3@xiaomi.com> Co-authored-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
parent
d8d367b367
commit
a290aaf93e
|
@ -1691,7 +1691,13 @@ init_function_local_offsets(WASMFunction *func,
|
||||||
uint32 i, local_offset = 0;
|
uint32 i, local_offset = 0;
|
||||||
uint64 total_size = sizeof(uint16) * ((uint64)param_count + local_count);
|
uint64 total_size = sizeof(uint16) * ((uint64)param_count + local_count);
|
||||||
|
|
||||||
if (!(func->local_offsets =
|
/*
|
||||||
|
* Only allocate memory when total_size is not 0,
|
||||||
|
* or the return value of malloc(0) might be NULL on some platforms,
|
||||||
|
* which causes wasm loader return false.
|
||||||
|
*/
|
||||||
|
if (total_size > 0
|
||||||
|
&& !(func->local_offsets =
|
||||||
loader_malloc(total_size, error_buf, error_buf_size))) {
|
loader_malloc(total_size, error_buf, error_buf_size))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -853,7 +853,8 @@ init_function_local_offsets(WASMFunction *func,
|
||||||
uint32 i, local_offset = 0;
|
uint32 i, local_offset = 0;
|
||||||
uint64 total_size = sizeof(uint16) * ((uint64)param_count + local_count);
|
uint64 total_size = sizeof(uint16) * ((uint64)param_count + local_count);
|
||||||
|
|
||||||
if (!(func->local_offsets =
|
if (total_size > 0
|
||||||
|
&& !(func->local_offsets =
|
||||||
loader_malloc(total_size, error_buf, error_buf_size))) {
|
loader_malloc(total_size, error_buf, error_buf_size))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user