objdump, nm: sprintf sanitizer null destination pointer
Seen on Ubuntu 23.04 x86_64-linux using gcc-12.2 and gcc-12.3 with
CFLAGS="-m32 -g -O2 -fsanitize=address,undefined".
CC objdump.o
In file included from /usr/include/stdio.h:906,
from /home/alan/src/binutils-gdb/binutils/sysdep.h:24,
from /home/alan/src/binutils-gdb/binutils/objdump.c:51:
In function 'sprintf',
inlined from 'display_utf8' at /home/alan/src/binutils-gdb/binutils/objdump.c:621:14,
inlined from 'sanitize_string.part.0' at /home/alan/src/binutils-gdb/binutils/objdump.c:742:11:
/usr/include/bits/stdio2.h:30:10: error: null destination pointer [-Werror=format-overflow=]
30 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
The warning is bogus of course. xmalloc is guaranteed to return
non-NULL, but apparently this isn't seen in display_utf6. The same
doesn't happen with -m64, maybe due to inlining differences, I haven't
investigated fully. Easily avoided as we hardly need to use sprintf
for a single char, or a two char string.
* objdump.c (display_utf8): Avoid bogus sprintf sanitizer warning.
Use hex ESC to switch back to default colour.
(sanitize_string): Comment. Bump buffer size by one. Fix overlong
line.
* nm.c (display_utf8, sanitize_string): As above.