Fix warnings/issues reported in Windows and by CodeQL/Coverity (#3275)

Fix the warnings and issues reported:
- in Windows platform
- by CodeQL static code analyzing
- by Coverity static code analyzing

And update CodeQL script to build exception handling and memory features.
This commit is contained in:
Wenyong Huang
2024-04-07 11:57:31 +08:00
committed by GitHub
parent 53f0941ffa
commit 2013f1f7d7
26 changed files with 202 additions and 118 deletions

View File

@ -148,7 +148,7 @@ wasm_dump_func_type(const WASMFuncType *type)
os_printf("] -> [");
for (; i < type->param_count + type->result_count; i++) {
for (; i < (uint32)(type->param_count + type->result_count); i++) {
if (wasm_is_type_multi_byte_type(type->types[i])) {
bh_assert(j < type->ref_type_map_count);
bh_assert(i == type->ref_type_maps[j].index);
@ -264,7 +264,7 @@ wasm_func_type_equal(const WASMFuncType *type1, const WASMFuncType *type2,
|| type1->ref_type_map_count != type2->ref_type_map_count)
return false;
for (i = 0; i < type1->param_count + type1->result_count; i++) {
for (i = 0; i < (uint32)(type1->param_count + type1->result_count); i++) {
if (type1->types[i] != type2->types[i])
return false;
@ -399,7 +399,7 @@ wasm_func_type_is_subtype_of(const WASMFuncType *type1,
}
}
for (; i < type1->param_count + type1->result_count; i++) {
for (; i < (uint32)(type1->param_count + type1->result_count); i++) {
if (wasm_is_type_multi_byte_type(type1->types[i])) {
bh_assert(j1 < type1->ref_type_map_count);
ref_type1 = type1->ref_type_maps[j1++].ref_type;

View File

@ -3987,7 +3987,7 @@ wasm_table_get(const wasm_table_t *table, wasm_table_size_t index)
if (index >= table_interp->cur_size) {
return NULL;
}
ref_idx = table_interp->elems[index];
ref_idx = (uint32)table_interp->elems[index];
}
#endif
@ -3998,7 +3998,7 @@ wasm_table_get(const wasm_table_t *table, wasm_table_size_t index)
if (index >= table_aot->cur_size) {
return NULL;
}
ref_idx = table_aot->elems[index];
ref_idx = (uint32)table_aot->elems[index];
}
#endif

View File

@ -41,12 +41,12 @@ static void (*free_func)(void *ptr) = NULL;
static unsigned int global_pool_size;
static uint32
static uint64
align_as_and_cast(uint64 size, uint64 alignment)
{
uint64 aligned_size = (size + alignment - 1) & ~(alignment - 1);
return aligned_size > UINT32_MAX ? UINT32_MAX : (uint32)aligned_size;
return aligned_size;
}
static bool
@ -951,7 +951,7 @@ wasm_allocate_linear_memory(uint8 **data, bool is_shared_memory,
{
bh_assert(*memory_data_size <= MAX_LINEAR_MEMORY_SIZE);
}
align_as_and_cast(*memory_data_size, page_size);
*memory_data_size = align_as_and_cast(*memory_data_size, page_size);
if (map_size > 0) {
if (!(*data = wasm_mmap_linear_memory(map_size, *memory_data_size))) {
@ -960,4 +960,4 @@ wasm_allocate_linear_memory(uint8 **data, bool is_shared_memory,
}
return BHT_OK;
}
}

View File

@ -275,11 +275,11 @@ decode_insn(uint8 *insn)
buffer, sizeof(buffer),
runtime_address);
#if 0
/* Print current instruction */
/*
os_printf("%012" PRIX64 " ", runtime_address);
puts(buffer);
*/
#endif
return instruction.length;
}
@ -1043,7 +1043,7 @@ wasm_runtime_register_module_internal(const char *module_name,
/* module hasn't been registered */
node = runtime_malloc(sizeof(WASMRegisteredModule), NULL, NULL, 0);
if (!node) {
LOG_DEBUG("malloc WASMRegisteredModule failed. SZ=%d",
LOG_DEBUG("malloc WASMRegisteredModule failed. SZ=%zu",
sizeof(WASMRegisteredModule));
return false;
}
@ -1780,7 +1780,7 @@ wasm_runtime_dump_mem_consumption(WASMExecEnv *exec_env)
wasm_runtime_dump_module_inst_mem_consumption(module_inst_common);
wasm_runtime_dump_exec_env_mem_consumption(exec_env);
os_printf("\nTotal memory consumption of module, module inst and "
"exec env: %u\n",
"exec env: %" PRIu64 "\n",
total_size);
os_printf("Total interpreter stack used: %u\n",
exec_env->max_wasm_stack_used);
@ -5488,6 +5488,7 @@ wasm_externref_set_cleanup(WASMModuleInstanceCommon *module_inst,
if (lookup_user_data.found) {
void *key = (void *)(uintptr_t)lookup_user_data.externref_idx;
ExternRefMapNode *node = bh_hash_map_find(externref_map, key);
bh_assert(node);
node->cleanup = extern_obj_cleanup;
ok = true;
}
@ -6539,12 +6540,12 @@ wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
if (!ret) {
LOG_DEBUG("read the file of %s failed", sub_module_name);
set_error_buf_v(parent_module, error_buf, error_buf_size,
"unknown import", sub_module_name);
"unknown import %s", sub_module_name);
goto delete_loading_module;
}
if (get_package_type(buffer, buffer_size) != parent_module->module_type) {
LOG_DEBUG("moudle %s type error", sub_module_name);
goto delete_loading_module;
goto destroy_file_buffer;
}
if (get_package_type(buffer, buffer_size) == Wasm_Module_Bytecode) {
#if WASM_ENABLE_INTERP != 0
@ -6650,7 +6651,7 @@ wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
sub_module_inst_list_node = loader_malloc(sizeof(WASMSubModInstNode),
error_buf, error_buf_size);
if (!sub_module_inst_list_node) {
LOG_DEBUG("Malloc WASMSubModInstNode failed, SZ:%d",
LOG_DEBUG("Malloc WASMSubModInstNode failed, SZ: %zu",
sizeof(WASMSubModInstNode));
if (sub_module_inst)
wasm_runtime_deinstantiate_internal(sub_module_inst, false);