mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-07-30 21:34:42 +08:00
gdb: fix undefined behavior reported in copy_bitwise
gdb version 9.1, built with clang 8.0.0 on Ubuntu 18.04 (x86_64); --enable-ubsan (for clang's undefined behavior sanitizer) Executing command; `maint selftest copy_bitwise` bombs in runtime error: ../../gdb/utils.c:3432:28: runtime error: left shift of negative value -1 Closer look reveals the offending shift: `(~0 << nbits)`, apparently 0 is treated as signed int, resulting in negative complement. Explicitly stating it unsigned 0U fixes it and the `copy_bitwise` test passes ok.
This commit is contained in:

committed by
Simon Marchi

parent
de7ac122a7
commit
cf83625da2
@ -3433,7 +3433,7 @@ copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
|
||||
buf |= *source << avail;
|
||||
|
||||
buf &= (1 << nbits) - 1;
|
||||
*dest = (*dest & (~0 << nbits)) | buf;
|
||||
*dest = (*dest & (~0U << nbits)) | buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user