Skip to content

Commit

Permalink
Fix syscall_close error handling
Browse files Browse the repository at this point in the history
The current implementation of syscall_close lacks proper error
handling, potentially returning 0 even when an error occurs. This fix
introduces a check for fclose errors and updates the return value to
-1 in case of an error.
  • Loading branch information
visitorckw committed Dec 22, 2023
1 parent aeeb6e2 commit 331e7c4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ static void syscall_close(riscv_t *rv)
map_iter_t it;
map_find(s->fd_map, &it, &fd);
if (!map_at_end(s->fd_map, &it)) {
fclose(map_iter_value(&it, FILE *));
if (fclose(map_iter_value(&it, FILE *))) {
/* error */
rv_set_reg(rv, rv_reg_a0, -1);
return;
}
map_erase(s->fd_map, &it);

/* success */
Expand Down

0 comments on commit 331e7c4

Please sign in to comment.