Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
v1.16: programs/sbf: c/float: work on stack values (backport of #32192)…
Browse files Browse the repository at this point in the history
… (#32193)

programs/sbf: c/float: work on stack values (#32192)

Before this change the program was writing into the realloc region.
Direct mapping is going to  enforce permissions on the realloc region,
and the program doesn't have permissions to write, so move to working on
the stack to avoid access violation errors.

(cherry picked from commit 8757f8d)

Co-authored-by: Alessandro Decina <alessandro.d@gmail.com>
  • Loading branch information
mergify[bot] and alessandrod authored Jun 19, 2023
1 parent be9f285 commit 6368469
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions programs/sbf/c/src/float/float.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ extern uint64_t entrypoint(const uint8_t *input) {
return ERROR_INVALID_ARGUMENT;
}
/* test float conversion to int compiles and works */
uint32_t *data = (uint32_t *)(params.ka[0].data);
uint32_t new_data = *data + 1;
*data += 1.5;
sol_assert(*data == new_data);
uint32_t data = *(uint32_t *)(params.ka[0].data);
uint32_t new_data = data + 1;
data += 1.5;
sol_assert(data == new_data);

/* test signed division works for FP values */
double value = (double)new_data + 1.0;
value /= -2.0;
sol_assert(value < 0.0);

/* test that standard math functions are available */
value = *data + 1.0;
value = data + 1.0;
sol_assert(log2(value) == 1.0);

return SUCCESS;
Expand Down

0 comments on commit 6368469

Please sign in to comment.