aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-06-18 18:24:43 +0930
committerAlan Modra <amodra@gmail.com>2021-06-19 11:08:00 +0930
commit539b54f03dd082c572308246e610e516ff96b5b1 (patch)
treed5c7eb8cc110c302581899452756974d75e70e39 /binutils
parent8ee63c615688aeb997d01129a037068e606351bd (diff)
downloadfsf-binutils-gdb-539b54f03dd082c572308246e610e516ff96b5b1.zip
fsf-binutils-gdb-539b54f03dd082c572308246e610e516ff96b5b1.tar.gz
fsf-binutils-gdb-539b54f03dd082c572308246e610e516ff96b5b1.tar.bz2
dwarf.c: string_fortify.h strncpy error
In function 'strncpy', inlined from 'display_debug_lines_decoded' at /home/alan/src/binutils-gdb/binutils/dwarf.c:5434:5, inlined from 'display_debug_lines' at /home/alan/src/binutils-gdb/binutils/dwarf.c:5567:21: /usr/include/bits/string_fortified.h:95:10: error: '__builtin_strncpy' specified bound 36 equals destination size [-Werror=stringop-truncation] No need for strncpy here, the string being copied always fits the destination buffer. * dwarf.c (display_debug_lines_decoded): Use memcpy rather than strncpy when trimming file name length to MAX_FILENAME_LENGTH. Don't make an unnecessary copy when length is good.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog6
-rw-r--r--binutils/dwarf.c24
2 files changed, 14 insertions, 16 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 125dd2e..c6a05ca 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2021-06-19 Alan Modra <amodra@gmail.com>
+
+ * dwarf.c (display_debug_lines_decoded): Use memcpy rather than
+ strncpy when trimming file name length to MAX_FILENAME_LENGTH.
+ Don't make an unnecessary copy when length is good.
+
2021-06-18 H.J. Lu <hongjiu.lu@intel.com>
* readelf.c (print_gnu_property_note): Handle
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index ebc7b02..a57f0da 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -5426,31 +5426,22 @@ display_debug_lines_decoded (struct dwarf_section * section,
fileName = _("<unknown>");
fileNameLength = strlen (fileName);
-
- if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
+ newFileName = fileName;
+ if (fileNameLength > MAX_FILENAME_LENGTH && !do_wide)
{
newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
/* Truncate file name */
- strncpy (newFileName,
- fileName + fileNameLength - MAX_FILENAME_LENGTH,
- MAX_FILENAME_LENGTH + 1);
- /* FIXME: This is to pacify gcc-10 which can warn that the
- strncpy above might leave a non-NUL terminated string
- in newFileName. It won't, but gcc's analysis doesn't
- quite go far enough to discover this. */
+ memcpy (newFileName,
+ fileName + fileNameLength - MAX_FILENAME_LENGTH,
+ MAX_FILENAME_LENGTH);
newFileName[MAX_FILENAME_LENGTH] = 0;
}
- else
- {
- newFileName = (char *) xmalloc (fileNameLength + 1);
- strncpy (newFileName, fileName, fileNameLength + 1);
- }
/* A row with end_seq set to true has a meaningful address, but
the other information in the same row is not significant.
In such a row, print line as "-", and don't print
view/is_stmt. */
- if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
+ if (!do_wide || fileNameLength <= MAX_FILENAME_LENGTH)
{
if (linfo.li_max_ops_per_insn == 1)
{
@@ -5525,7 +5516,8 @@ display_debug_lines_decoded (struct dwarf_section * section,
putchar ('\n');
}
- free (newFileName);
+ if (newFileName != fileName)
+ free (newFileName);
}
}