Skip to content

Commit

Permalink
Merge pull request #265 from henrybear327/fix/null_ptr_deref
Browse files Browse the repository at this point in the history
Fix a potential issue where the block_find() might return NULL
  • Loading branch information
jserv authored Nov 16, 2023
2 parents 98ae1cf + 88f6e1b commit 1666a41
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,20 +1004,22 @@ void rv_step(riscv_t *rv, int32_t cycles)
if (prev->pc_start != last_pc)
prev = block_find(&rv->block_map, last_pc);

rv_insn_t *last_ir = prev->ir_tail;
/* chain block */
if (!insn_is_unconditional_branch(last_ir->opcode)) {
if (is_branch_taken && !last_ir->branch_taken)
last_ir->branch_taken = block->ir_head;
else if (!last_ir->branch_untaken)
last_ir->branch_untaken = block->ir_head;
} else if (IF_insn(last_ir, jal)
if (prev) {
rv_insn_t *last_ir = prev->ir_tail;
/* chain block */
if (!insn_is_unconditional_branch(last_ir->opcode)) {
if (is_branch_taken && !last_ir->branch_taken)
last_ir->branch_taken = block->ir_head;
else if (!last_ir->branch_untaken)
last_ir->branch_untaken = block->ir_head;
} else if (IF_insn(last_ir, jal)
#if RV32_HAS(EXT_C)
|| IF_insn(last_ir, cj) || IF_insn(last_ir, cjal)
|| IF_insn(last_ir, cj) || IF_insn(last_ir, cjal)
#endif
) {
if (!last_ir->branch_taken)
last_ir->branch_taken = block->ir_head;
) {
if (!last_ir->branch_taken)
last_ir->branch_taken = block->ir_head;
}
}
}
last_pc = rv->PC;
Expand Down

0 comments on commit 1666a41

Please sign in to comment.