Fix issues reported by klocwork (#1060)

Fix issues reported by klocwork, fix host_tool compile error,
and update build script of benchmark jetstream
This commit is contained in:
Wenyong Huang 2022-03-24 17:34:22 +08:00 committed by GitHub
parent 7262aebf77
commit 5264ce4118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 13 deletions

View File

@ -322,7 +322,8 @@ wasm_engine_new()
singleton_engine =
wasm_engine_new_internal(Alloc_With_System_Allocator, NULL);
}
singleton_engine->ref_count++;
if (singleton_engine)
singleton_engine->ref_count++;
return singleton_engine;
}
@ -339,7 +340,8 @@ wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
if (!singleton_engine) {
singleton_engine = wasm_engine_new_internal(type, opts);
}
singleton_engine->ref_count++;
if (singleton_engine)
singleton_engine->ref_count++;
return singleton_engine;
}

View File

@ -1309,7 +1309,8 @@ wasm_runtime_finalize_call_function(WASMExecEnv *exec_env,
bh_assert((argv && ret_argv) || (argc == 0));
if (argv == ret_argv) {
if (argv == ret_argv || argc == 0) {
/* no need to transfrom externref results */
return true;
}
@ -2398,7 +2399,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
address = strtok(cp, "/");
mask = strtok(NULL, "/");
ret = addr_pool_insert(apool, address, (uint8)(atoi(mask)));
ret = addr_pool_insert(apool, address, (uint8)(mask ? atoi(mask) : 0));
wasm_runtime_free(cp);
if (!ret) {
set_error_buf(error_buf, error_buf_size,

View File

@ -224,6 +224,8 @@ on_rsp_byte_arrive(unsigned char ch, rsp_recv_context_t *ctx)
if (ctx->size_in_phase == 2) {
ctx->size_in_phase = 0;
bh_assert(ctx->receive_index >= 3);
if ((hex(ctx->receive_buffer[ctx->receive_index - 2]) << 4
| hex(ctx->receive_buffer[ctx->receive_index - 1]))
!= ctx->check_sum) {

View File

@ -2910,7 +2910,7 @@ wasi_ssp_sock_open(
error =
fd_determine_type_rights(sock, &wasi_type, &max_base, &max_inheriting);
if (error != __WASI_ESUCCESS) {
os_socket_close(ret);
os_socket_close(sock);
return error;
}
@ -2925,7 +2925,7 @@ wasi_ssp_sock_open(
error = fd_table_insert_fd(curfds, sock, wasi_type, max_base,
max_inheriting, sockfd);
if (error != __WASI_ESUCCESS) {
os_socket_close(ret);
os_socket_close(sock);
return error;
}

View File

@ -74,7 +74,7 @@ bh_vector_init(Vector *vector, size_t init_length, size_t size_elem,
vector->lock = NULL;
if (use_lock) {
if (!(vector->lock = wasm_runtime_malloc(sizeof(korp_mutex)))) {
if (!(vector->lock = BH_MALLOC(sizeof(korp_mutex)))) {
LOG_ERROR("Init vector failed: alloc locker failed.\n");
bh_vector_destroy(vector);
return false;
@ -83,7 +83,7 @@ bh_vector_init(Vector *vector, size_t init_length, size_t size_elem,
if (BHT_OK != os_mutex_init(vector->lock)) {
LOG_ERROR("Init vector failed: init locker failed.\n");
wasm_runtime_free(vector->lock);
BH_FREE(vector->lock);
vector->lock = NULL;
bh_vector_destroy(vector);
@ -251,7 +251,7 @@ bh_vector_destroy(Vector *vector)
if (vector->lock) {
os_mutex_destroy(vector->lock);
wasm_runtime_free(vector->lock);
BH_FREE(vector->lock);
}
memset(vector, 0, sizeof(Vector));

View File

@ -15,6 +15,10 @@ void print_mutability(wasm_mutability_t mut) {
}
void print_limits(const wasm_limits_t* limits) {
if (!limits) {
printf("unknown limits");
return;
}
printf("%ud", limits->min);
if (limits->max < wasm_limits_max_default) printf(" %ud", limits->max);
}
@ -43,6 +47,10 @@ void print_valtypes(const wasm_valtype_vec_t* types) {
}
void print_externtype(const wasm_externtype_t* type) {
if (!type) {
printf("unknown extern type");
return;
}
switch (wasm_externtype_kind(type)) {
case WASM_EXTERN_FUNC: {
const wasm_functype_t* functype =
@ -78,6 +86,10 @@ void print_externtype(const wasm_externtype_t* type) {
}
void print_name(const wasm_name_t* name) {
if (!name) {
printf("unknown name");
return;
}
printf("\"%.*s\"", (int)name->size, name->data);
}

View File

@ -25,8 +25,9 @@ g++ -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/gcc-loops_native gcc-loops.cpp
echo "Build gcc-loops with em++ .."
em++ -O3 -s STANDALONE_WASM=1 -msimd128 \
-s INITIAL_MEMORY=1048576 \
-s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=32768 \
-s TOTAL_STACK=32768 \
-s "EXPORTED_FUNCTIONS=['_main']" \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-o ${OUT_DIR}/gcc-loops.wasm gcc-loops.cpp
echo "Compile gcc-loops.wasm to gcc-loops.aot"
@ -38,7 +39,7 @@ gcc -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/quicksort_native quicksort.c
echo "Build quicksort with emcc .."
emcc -O3 -s STANDALONE_WASM=1 -msimd128 \
-s INITIAL_MEMORY=1048576 \
-s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=32768 \
-s TOTAL_STACK=32768 \
-s "EXPORTED_FUNCTIONS=['_main']" \
-o ${OUT_DIR}/quicksort.wasm quicksort.c
@ -52,7 +53,7 @@ g++ -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/HashSet_native HashSet.cpp \
echo "Build HashSet with em++ .."
em++ -O3 -s STANDALONE_WASM=1 -msimd128 \
-s INITIAL_MEMORY=1048576 \
-s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=32768 \
-s TOTAL_STACK=32768 \
-s "EXPORTED_FUNCTIONS=['_main']" \
-o ${OUT_DIR}/HashSet.wasm HashSet.cpp
@ -65,7 +66,7 @@ gcc -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/float-mm_native float-mm.c
echo "Build float-mm with emcc .."
emcc -O3 -s STANDALONE_WASM=1 -msimd128 \
-s INITIAL_MEMORY=1048576 \
-s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=32768 \
-s TOTAL_STACK=32768 \
-s "EXPORTED_FUNCTIONS=['_main']" \
-o ${OUT_DIR}/float-mm.wasm float-mm.c