Skip to content

Commit 16ee11a

Browse files
authored
Merge pull request #77 from EricccTaiwan/master
Initialize harts with zero properly
2 parents 430b960 + 72ade5f commit 16ee11a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

main.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,11 @@ static int semu_init(emu_state_t *emu, int argc, char **argv)
650650
vm->n_hart = hart_count;
651651
vm->hart = malloc(sizeof(hart_t *) * vm->n_hart);
652652
for (uint32_t i = 0; i < vm->n_hart; i++) {
653-
hart_t *newhart = malloc(sizeof(hart_t));
653+
hart_t *newhart = calloc(1, sizeof(hart_t));
654+
if (!newhart) {
655+
fprintf(stderr, "Failed to allocate hart #%u.\n", i);
656+
return 1;
657+
}
654658
INIT_HART(newhart, emu, i);
655659
newhart->x_regs[RV_R_A0] = i;
656660
newhart->x_regs[RV_R_A1] = dtb_addr;

0 commit comments

Comments
 (0)