Skip to content

Commit 1e4ef3c

Browse files
committed
Initialize ir->branch_table->PC with safe value
If the ra(return address) is 0x0, the LOOKUP_OR_UPDATE_BRANCH_HISTORY_TABLE will bahave abnormally since calloc initialize ir->branch_table->PC[i] to 0x0. The 0x0 address might be not yet translated to a valid block, thus ir->branch_table->target[i] might be NULL, calling a NULL function pointer cause segmentation fault. It can be solved by initializing ir->branch_table->PC will other value than 0x0. Here, I choose unsigned integer of -1. Close #461
1 parent ef151e2 commit 1e4ef3c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/emulate.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ static void block_translate(riscv_t *rv, block_t *block)
617617
) {
618618
ir->branch_table = calloc(1, sizeof(branch_history_table_t));
619619
assert(ir->branch_table);
620+
memset(ir->branch_table->PC, -1,
621+
sizeof(uint32_t) * HISTORY_SIZE);
620622
}
621623
break;
622624
}

0 commit comments

Comments
 (0)