aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-tasks.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-03-20 07:30:13 -0600
committerTom Tromey <tromey@adacore.com>2020-03-20 08:31:17 -0600
commitf67210ff1c4200ea668189d086c6b39145cd876f (patch)
tree8eade1f1e0acf3beb6782761f22b53223bd10bcc /gdb/ada-tasks.c
parent1773be9ea2207d42442222e6dc3c8fdbe638e28e (diff)
downloadgdb-f67210ff1c4200ea668189d086c6b39145cd876f.zip
gdb-f67210ff1c4200ea668189d086c6b39145cd876f.tar.gz
gdb-f67210ff1c4200ea668189d086c6b39145cd876f.tar.bz2
Avoid stringop-truncation errors
I configured with -fsanitize=address and built gdb. linux-tdep.c and ada-tasks.c failed to build due to some stringop-truncation errors, e.g.: In function ‘char* strncpy(char*, const char*, size_t)’, inlined from ‘int linux_fill_prpsinfo(elf_internal_linux_prpsinfo*)’ at ../../binutils-gdb/gdb/linux-tdep.c:1742:11, inlined from ‘char* linux_make_corefile_notes(gdbarch*, bfd*, int*)’ at ../../binutils-gdb/gdb/linux-tdep.c:1878:27: /usr/include/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 81 equals destination size [-Werror=stringop-truncation] This patch fixes the problem by using "sizeof - 1" in the call to strndup, as recommended in the GCC manual. This doesn't make a difference here because the next line, in all cases, sets the final element to '\0' anyway. gdb/ChangeLog 2020-03-20 Tom Tromey <tromey@adacore.com> * ada-tasks.c (read_atcb): Use smaller length in strncpy call. * linux-tdep.c (linux_fill_prpsinfo): Use smaller length in strncpy call.
Diffstat (limited to 'gdb/ada-tasks.c')
-rw-r--r--gdb/ada-tasks.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 0a81c3c..589d5e8 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -679,7 +679,8 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
task_name = p + 2;
/* Copy the task name. */
- strncpy (task_info->name, task_name, sizeof (task_info->name));
+ strncpy (task_info->name, task_name,
+ sizeof (task_info->name) - 1);
task_info->name[sizeof (task_info->name) - 1] = 0;
}
else