binutils-gdb/gdb/nat
Tom Tromey 5917321695 Fix ubsan build
I tried a build using the undefined behavior sanitizer, and gcc gave
this error:

In file included from /usr/include/string.h:495,
                 from ../gnulib/import/string.h:41,
                 from ../../binutils-gdb/gdb/../gdbsupport/common-defs.h:95,
                 from ../../binutils-gdb/gdb/nat/linux-osdata.c:20:
In function 'char* strncpy(char*, const char*, size_t)',
    inlined from 'void time_from_time_t(char*, int, TIME_T)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:923:15,
    inlined from 'void time_from_time_t(char*, int, TIME_T)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:911:1,
    inlined from 'void linux_xfer_osdata_sem(buffer*)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:1082:22:
/usr/include/bits/string_fortified.h:106:34: error: 'char* __builtin_strncpy(char*, const char*, long unsigned int)' specified bound 32 equals destination size [-Werror=stringop-truncation]

This patch fixes the problem by subtracting one from the length
parameter to strncpy.

I changed a couple of other similar functions -- gcc does not warn
about these, but I didn't see any substantial difference between the
different cases, and I think these are just latent warnings, to be
triggered in the future by a change to inlining heuristics.

gdb/ChangeLog
2021-05-17  Tom Tromey  <tromey@adacore.com>

	* nat/linux-osdata.c (user_from_uid, time_from_time_t)
	(group_from_gid): Subtract one from strncpy length.
2021-05-17 13:06:05 -06:00
..
aarch64-linux-hw-point.c Add comment regarding include order of <sys/ptrace.h> and <asm/ptrace.h> 2021-02-24 14:35:07 -07:00
aarch64-linux-hw-point.h
aarch64-linux.c
aarch64-linux.h
aarch64-mte-linux-ptrace.c [AArch64] Fix include order for MTE 2021-04-09 11:36:55 -03:00
aarch64-mte-linux-ptrace.h AArch64: Implement memory tagging target methods for AArch64 2021-03-24 14:53:56 -03:00
aarch64-sve-linux-ptrace.c
aarch64-sve-linux-ptrace.h Add comment regarding include order of <sys/ptrace.h> and <asm/ptrace.h> 2021-02-25 15:30:32 -07:00
aarch64-sve-linux-sigcontext.h
amd64-linux-siginfo.c amd64-linux-siginfo.c: Adjust include order to avoid gnulib error 2021-02-18 22:56:56 -07:00
amd64-linux-siginfo.h
fork-inferior.c
fork-inferior.h
gdb_ptrace.h
gdb_thread_db.h
glibc_thread_db.h
linux-btrace.c
linux-btrace.h
linux-namespaces.c
linux-namespaces.h
linux-nat.h
linux-osdata.c Fix ubsan build 2021-05-17 13:06:05 -06:00
linux-osdata.h
linux-personality.c Don't run personality syscall at configure time; don't check it at all 2021-05-08 13:45:36 +01:00
linux-personality.h
linux-procfs.c
linux-procfs.h
linux-ptrace.c
linux-ptrace.h
linux-waitpid.c gdb, gdbserver: make status_to_str display the signal name 2021-05-10 12:13:36 -04:00
linux-waitpid.h gdb, gdbserver: make status_to_str return std::string 2021-05-08 21:07:20 -04:00
mips-linux-watch.c
mips-linux-watch.h
netbsd-nat.c
netbsd-nat.h
ppc-linux.c
ppc-linux.h
riscv-linux-tdesc.c
riscv-linux-tdesc.h
windows-nat.c Make get_image_name static 2021-04-30 10:22:24 -06:00
windows-nat.h Make get_image_name static 2021-04-30 10:22:24 -06:00
x86-cpuid.h
x86-dregs.c
x86-dregs.h
x86-gcc-cpuid.h
x86-linux-dregs.c
x86-linux-dregs.h
x86-linux.c
x86-linux.h