diff options
| author | Michael Sawyer <mjfsawyer@gmail.com> | 2024-09-06 19:28:35 -0400 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-09-19 15:00:06 +1000 |
| commit | b05983ff6d684561c8db6257ff816ef2e8114db5 (patch) | |
| tree | f9347fafdfb13ec713a932273e4141359d6b0dbc | |
| parent | 8b35f2c7fad87198c4ccab243cb3e8a61c7d0f3c (diff) | |
unix/modffi: Fix signed integer cast in return_ffi_value.
Casting an ffi_arg to a signed int may truncate the value. E.g., when the
ffi_arg is 64-bit and the signed int is 32-bit. Also, casting an ffi_arg
to a larger signed type will not sign extend the value. E.g., when the
ffi_arg is 32-bit and the larger signed type is int64_t. If the value is
signed, it should be cast to ffi_sarg, which is the same size as ffi_arg.
Signed-off-by: Michael Sawyer <mjfsawyer@gmail.com>
| -rw-r--r-- | ports/unix/modffi.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c index b3cd3380c..51beb355f 100644 --- a/ports/unix/modffi.c +++ b/ports/unix/modffi.c @@ -190,7 +190,7 @@ static mp_obj_t return_ffi_value(ffi_union_t *val, char type) { case 'h': case 'i': case 'l': - return mp_obj_new_int((signed)val->ffi); + return mp_obj_new_int((ffi_sarg)val->ffi); case 'B': case 'H': case 'I': |
