Skip to content

Commit b5189db

Browse files
authored
Fix issues reported by Coverity static analysis (bytecodealliance#1974)
1 parent 4837b15 commit b5189db

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

core/iwasm/common/wasm_c_api.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,15 +1657,14 @@ wasm_val_to_rt_val(WASMModuleInstanceCommon *inst_comm_rt, uint8 val_type_rt,
16571657
ret =
16581658
wasm_externref_obj2ref(inst_comm_rt, v->of.ref, (uint32 *)data);
16591659
break;
1660-
#else
1661-
(void)inst_comm_rt;
16621660
#endif
16631661
default:
16641662
LOG_WARNING("unexpected value type %d", val_type_rt);
16651663
ret = false;
16661664
break;
16671665
}
16681666

1667+
(void)inst_comm_rt;
16691668
return ret;
16701669
}
16711670

core/iwasm/fast-jit/jit_ir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ address_of_const(JitCompContext *cc, JitReg reg, unsigned size)
560560
unsigned no = jit_reg_no(reg);
561561
unsigned idx = no & ~_JIT_REG_CONST_IDX_FLAG;
562562

563+
bh_assert(kind < JIT_REG_KIND_L32);
563564
bh_assert(jit_reg_is_const_idx(reg) && idx < cc->_const_val._num[kind]);
564565

565566
return cc->_const_val._value[kind] + size * idx;
@@ -572,6 +573,7 @@ next_of_const(JitCompContext *cc, JitReg reg)
572573
unsigned no = jit_reg_no(reg);
573574
unsigned idx = no & ~_JIT_REG_CONST_IDX_FLAG;
574575

576+
bh_assert(kind < JIT_REG_KIND_L32);
575577
bh_assert(jit_reg_is_const_idx(reg) && idx < cc->_const_val._num[kind]);
576578

577579
return cc->_const_val._next[kind][idx];

core/iwasm/fast-jit/jit_ir.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,7 @@ jit_cc_is_hreg(JitCompContext *cc, JitReg reg)
16881688
unsigned kind = jit_reg_kind(reg);
16891689
unsigned no = jit_reg_no(reg);
16901690
bh_assert(jit_reg_is_variable(reg));
1691+
bh_assert(kind < JIT_REG_KIND_L32);
16911692
return no < cc->hreg_info->info[kind].num;
16921693
}
16931694

@@ -1705,6 +1706,7 @@ jit_cc_is_hreg_fixed(JitCompContext *cc, JitReg reg)
17051706
unsigned kind = jit_reg_kind(reg);
17061707
unsigned no = jit_reg_no(reg);
17071708
bh_assert(jit_cc_is_hreg(cc, reg));
1709+
bh_assert(kind < JIT_REG_KIND_L32);
17081710
return !!cc->hreg_info->info[kind].fixed[no];
17091711
}
17101712

@@ -1722,6 +1724,7 @@ jit_cc_is_hreg_caller_saved_native(JitCompContext *cc, JitReg reg)
17221724
unsigned kind = jit_reg_kind(reg);
17231725
unsigned no = jit_reg_no(reg);
17241726
bh_assert(jit_cc_is_hreg(cc, reg));
1727+
bh_assert(kind < JIT_REG_KIND_L32);
17251728
return !!cc->hreg_info->info[kind].caller_saved_native[no];
17261729
}
17271730

@@ -1739,6 +1742,7 @@ jit_cc_is_hreg_caller_saved_jitted(JitCompContext *cc, JitReg reg)
17391742
unsigned kind = jit_reg_kind(reg);
17401743
unsigned no = jit_reg_no(reg);
17411744
bh_assert(jit_cc_is_hreg(cc, reg));
1745+
bh_assert(kind < JIT_REG_KIND_L32);
17421746
return !!cc->hreg_info->info[kind].caller_saved_jitted[no];
17431747
}
17441748

core/iwasm/fast-jit/jit_regalloc.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ rc_get_vr(RegallocContext *rc, JitReg vreg)
156156
unsigned no = jit_reg_no(vreg);
157157

158158
bh_assert(jit_reg_is_variable(vreg));
159+
bh_assert(kind < JIT_REG_KIND_L32);
159160

160161
return &rc->vregs[kind][no];
161162
}
@@ -175,6 +176,7 @@ rc_get_hr(RegallocContext *rc, JitReg hreg)
175176
unsigned no = jit_reg_no(hreg);
176177

177178
bh_assert(jit_reg_is_variable(hreg) && jit_cc_is_hreg(rc->cc, hreg));
179+
bh_assert(kind < JIT_REG_KIND_L32);
178180

179181
return &rc->hregs[kind][no];
180182
}
@@ -208,7 +210,9 @@ static unsigned
208210
get_reg_stride(JitReg reg)
209211
{
210212
static const uint8 strides[] = { 0, 1, 2, 1, 2, 2, 4, 8, 0 };
211-
return strides[jit_reg_kind(reg)];
213+
uint32 kind = jit_reg_kind(reg);
214+
bh_assert(kind <= JIT_REG_KIND_L32);
215+
return strides[kind];
212216
}
213217

214218
/**
@@ -582,13 +586,17 @@ static JitReg
582586
allocate_hreg(RegallocContext *rc, JitReg vreg, JitInsn *insn, int distance)
583587
{
584588
const int kind = jit_reg_kind(vreg);
585-
const HardReg *hregs = rc->hregs[kind];
586-
const unsigned hreg_num = jit_cc_hreg_num(rc->cc, kind);
589+
const HardReg *hregs;
590+
unsigned hreg_num;
587591
JitReg hreg, vreg_to_reload = 0;
588592
int min_distance = distance, vr_distance;
589593
VirtualReg *vr = rc_get_vr(rc, vreg);
590594
unsigned i;
591595

596+
bh_assert(kind < JIT_REG_KIND_L32);
597+
hregs = rc->hregs[kind];
598+
hreg_num = jit_cc_hreg_num(rc->cc, kind);
599+
592600
if (hreg_num == 0)
593601
/* Unsupported hard register kind. */
594602
{

core/shared/platform/common/posix/posix_thread.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
6161
pthread_attr_init(&tattr);
6262
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);
6363
if (pthread_attr_setstacksize(&tattr, stack_size) != 0) {
64-
os_printf("Invalid thread stack size %u. Min stack size on Linux = %u",
65-
stack_size, PTHREAD_STACK_MIN);
64+
os_printf("Invalid thread stack size %u. "
65+
"Min stack size on Linux = %u\n",
66+
stack_size, (unsigned int)PTHREAD_STACK_MIN);
6667
pthread_attr_destroy(&tattr);
6768
return BHT_ERROR;
6869
}

0 commit comments

Comments
 (0)