librz/arch/c166: Coverity fixes

* CID: 909863
* CID: 909871
* CID: 909855
* CID: 909865
* CID: 909864
* CID: 909872
* CID: 909867
* CID: 909843
* CID: 909847
* CID: 909873
* CID 909856
This commit is contained in:
SSharshunov 2026-07-08 21:20:49 +05:00 committed by GitHub
parent f941f85187
commit eda5e12b56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 30 deletions

View file

@ -561,9 +561,6 @@ static ut8 c166_instr_mov_nm(C166_Inst *instr) {
swap = true;
format = FMT3;
break;
case C166_MOV_oRwn_oRwm: ///< 0xC8 [Rwn], [Rwm]
case C166_MOVB_oRwn_oRwm: ///< 0xC9 [Rwn], [Rwm]
format = FMT4;
break;
case C166_MOV_oRwnp_oRwm: ///< 0xD8 [Rwn+], [Rwm]
case C166_MOVB_oRwnp_oRwm: ///< 0xD9 [Rwn+], [Rwm]
@ -573,7 +570,11 @@ static ut8 c166_instr_mov_nm(C166_Inst *instr) {
case C166_MOVB_oRwn_oRwmp: ///< 0xE9 [Rwn], [Rwm+]
format = FMT6;
break;
default: break;
case C166_MOV_oRwn_oRwm: ///< 0xC8 [Rwn], [Rwm]
case C166_MOVB_oRwn_oRwm: ///< 0xC9 [Rwn], [Rwm]
default:
format = FMT4;
break;
}
// clang-format on
if (swap) {
@ -979,10 +980,6 @@ static const char *c166_instr_extended_name(C166_Inst *instr) {
return "CoNEG";
}
if ((opcode == 0x83) && (extID == 0x9A)) {
return "CoSHR";
}
if ((opcode == 0x93) && (extID == 0x5A)) {
return "CoNOP";
}
@ -1391,8 +1388,6 @@ static ut8 c166_instr_extended(C166_Inst *instr) {
goto end;
} else if ((opcode == 0xA3) && (extID == 0x32)) {
goto end;
} else if ((opcode == 0xA3) && (extID == 0xB2)) {
goto end;
} else if ((opcode == 0x83) && (extID == 0x8A)) {
OPERANDS("[r%i]", m); // ????? CoSHL [RWm*]
goto end;

View file

@ -495,10 +495,6 @@ static void c166_op_call_seg_caddr(RzAnalysis *analysis, RzAnalysisOp *op, const
op->stackop = RZ_ANALYSIS_STACK_INC;
op->stackptr = 4;
ut8 SP = (ut8)GET_A_SP;
SET_A_SP((ut64)SP - 2);
SP = (ut8)GET_A_SP;
const ut8 SGTDIS = (ut8)GET_A_SGTDIS;
if (SGTDIS == 0) {
if (!SET_A_CSP((ut64)seg)) {
@ -538,12 +534,6 @@ static void c166_op_pcall_reg_caddr(RzAnalysis *analysis, RzAnalysisOp *op, cons
const ut16 caddr = rz_read_at_le16(buf, 2);
op->stackop = RZ_ANALYSIS_STACK_INC;
op->stackptr = 4;
ut8 SP = (ut8)GET_A_SP;
SET_A_SP((ut64)SP - 2);
SP = (ut8)GET_A_SP;
SET_A_IP((ut64)caddr);
op->type = RZ_ANALYSIS_OP_TYPE_UCALL;
c166_set_jump_target_from_caddr(op, caddr);
c166_set_mimo_addr_from_reg(op, buf[1]);

View file

@ -342,11 +342,13 @@ static st32 disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, st32 len) {
return op->size;
}
C166State *state = (C166State *)a->plugin_data;
if (!state) {
if (!a->plugin_data) {
RZ_LOG_FATAL("C166State was NULL.\n");
return -1;
}
C166State *state = (C166State *)a->plugin_data;
C166_Inst inst = RZ_EMPTY;
inst.addr = (ut32)a->pc;
if (check_unused_opcode(buf[0])) {
@ -360,8 +362,6 @@ static st32 disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, st32 len) {
rz_asm_op_setf_asm(op, FMT_2WORD, buf[0], buf[1], buf[2], 0x00);
} else if (op->size == 4 && len == 2) {
rz_asm_op_setf_asm(op, FMT_2WORD, buf[0], buf[1], 0x00, 0x00);
} else if (op->size == 2 && len == 1) {
rz_asm_op_setf_asm(op, FMT_WORD, buf[0], 0x00);
} else if (RZ_STR_EQ(inst.instr, "invalid")) {
if (op->size == 2)
rz_asm_op_setf_asm(op, FMT_WORD, buf[0], buf[1]);

View file

@ -584,7 +584,7 @@ static int load_linnum_data(const rz_bin_omf166_obj *obj, const ut8 *buf, const
}
linnum->LineNumber = rz_read_le16_offset(buf, &ct); // start with ct = 5
const ut16 offset = rz_read_le16_offset(buf, &ct);
linnum->address = (FrameNumber << 16) | offset;
linnum->address = ((ut64)FrameNumber << 16) | offset;
OMF_coments *comment = rz_pvector_tail(obj->coments_vec);
if (!comment) {
RZ_FREE(linnum);
@ -686,6 +686,9 @@ static int load_omf_unk4(const ut8 *buf, const size_t buf_size, const OMF_record
RZ_LOG_DEBUG("load_omf = UNKNOWN4 = [%05d] [0x%08" PFMT64x "] 0x%02x (%10" PFMTSZu ")\n", record->size, global_ct, record->type, buf_size);
size_t ct = 3;
const ut16 count = rz_read_le16_offset(buf, &ct);
if (count == 0 || count > UINT16_MAX) {
return false;
}
RZ_LOG_DEBUG("count: %2d [%02x %02x]\n%02x %02x\n",
count, buf[ct], buf[ct + 1], buf[ct + 2], buf[ct + 3]);
@ -833,9 +836,13 @@ static int load_omf_typnew(rz_bin_omf166_obj *obj, const ut8 *buf) {
* 0x20 | NrOfComp16 | Components [*] { TI16 | OFFS32 | REP8 | POS8 | n,name }
* \endcode
*/
const ut16 raw_count = rz_read_le16_offset(buf, &cct);
if (raw_count == 0 || raw_count > UINT16_MAX) {
return false;
}
newtype->label = rz_str_dup("COMPONENT_LIST_DESCRIPTOR");
newtype->descriptor.components.index = obj->TI_INDEX;
newtype->descriptor.components.count = rz_read_le16_offset(buf, &cct);
newtype->descriptor.components.count = raw_count;
newtype->descriptor.components.comp =
RZ_NEWS0(OMF_component, newtype->descriptor.components.count);
if (!newtype->descriptor.components.comp) {
@ -844,7 +851,7 @@ static int load_omf_typnew(rz_bin_omf166_obj *obj, const ut8 *buf) {
return false;
}
for (int i = 0; i < newtype->descriptor.components.count; i++) {
for (ut16 i = 0; i < newtype->descriptor.components.count; i++) {
OMF_component *component = newtype->descriptor.components.comp + i;
component->index = obj->TI_INDEX;
component->ti = rz_read_le16_offset(buf, &cct);
@ -1074,7 +1081,11 @@ static OMF_record *rz_bin_format_omf166_load_record(rz_bin_omf166_obj *obj, cons
}
size_t offset = 0;
new->type = rz_read_le8_offset(buf, &offset);
new->size = rz_read_le16_offset(buf, &offset);
const ut16 raw_count = rz_read_le16_offset(buf, &offset);
if (raw_count == 0 || raw_count > UINT16_MAX) {
return false;
}
new->size = raw_count;
// at least a record has a type, a size and a checksum
if (new->size > (buf_size - offset) || buf_size < (offset + 1)) {
@ -1082,7 +1093,7 @@ static OMF_record *rz_bin_format_omf166_load_record(rz_bin_omf166_obj *obj, cons
RZ_FREE(new);
return NULL;
}
if (!(rz_bin_format_omf166_load_content(obj, new, buf, global_ct, buf_size))) {
if (!rz_bin_format_omf166_load_content(obj, new, buf, global_ct, buf_size)) {
RZ_FREE(new);
return NULL;
}

View file

@ -55,7 +55,7 @@ static void destroy(RzBinFile *bf) {
}
rz_bin_omf166_obj *omf_obj = (rz_bin_omf166_obj *)bf->o->bin_obj;
if (omf_obj) {
if (!omf_obj) {
return;
}
ht_up_free(omf_obj->ht_types);