Fixed undefined behavior in UBSan.
This commit is contained in:
parent
d3f84ba724
commit
eec7f5da00
@ -158,9 +158,11 @@ static int64_t get_signed_val(FAR struct type_descriptor *type,
|
||||
if (is_inline_int(type))
|
||||
{
|
||||
unsigned extra_bits = sizeof(int64_t) * 8 - type_bit_width(type);
|
||||
uintptr_t ulong_val = (uintptr_t)val;
|
||||
uint64_t mask = (1llu << extra_bits) - 1;
|
||||
uint64_t ret = (uint64_t)val & mask;
|
||||
|
||||
return ((int64_t)ulong_val) << extra_bits >> extra_bits;
|
||||
return (int64_t)(((ret & (1llu << (extra_bits - 1))) != 0) ?
|
||||
ret | ~mask : ret);
|
||||
}
|
||||
|
||||
return *(FAR int64_t *)val;
|
||||
|
Loading…
Reference in New Issue
Block a user