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>
This commit is contained in:
committed by
Damien George
parent
8b35f2c7fa
commit
b05983ff6d
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user