]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb: fix undefined behavior reported in copy_bitwise
authorArtur Shepilko <nomadbyte@gmail.com>
Fri, 10 Apr 2020 14:56:43 +0000 (10:56 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 11 Apr 2020 01:04:03 +0000 (21:04 -0400)
commitcf83625da29d1239e97f1eb4d145f347cb741889
tree6b707b179bb60dbfbca74a14d8fd4af0f5a7d4c9
parentde7ac122a7f98c181c1ec175b0560bb48eabc6ea
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.
gdb/ChangeLog
gdb/utils.c