Skip to content

Commit

Permalink
Fix NULL pointer dereference in remove_next_nth_ir()
Browse files Browse the repository at this point in the history
There was a NULL pointer dereference issue in remove_next_nth_ir().
To address this, we now check for the existence of the next ir in the
loop. If there is no next ir, we terminate the loop early. This change
ensures that we do not attempt to remove non-existent ir.
  • Loading branch information
visitorckw committed Nov 4, 2023
1 parent 6294955 commit 66d4f43
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ static inline void remove_next_nth_ir(const riscv_t *rv,
{
for (uint8_t i = 0; i < n; i++) {
rv_insn_t *next = ir->next;
if (!next) {
n = i;
break;
}
ir->next = ir->next->next;
mpool_free(rv->block_ir_mp, next);
}
Expand Down

1 comment on commit 66d4f43

@jserv
Copy link
Contributor

@jserv jserv commented on 66d4f43 Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Benchmark suite Current: 66d4f43 Previous: 912e62e Ratio
Dhrystone 1720 Average DMIPS over 10 runs 1411.87 Average DMIPS over 10 runs 0.82
Coremark 1493.22 Average iterations/sec over 10 runs 1107.205 Average iterations/sec over 10 runs 0.74

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.