Commit: Fix s390 compile time warning with gcc-10

Message ID 87wo8yh89v.fsf@redhat.com
State New
Headers show
Series
  • Commit: Fix s390 compile time warning with gcc-10
Related show

Commit Message

Nick Clifton Feb. 7, 2020, 12:49 p.m.
Hi Guys,

  I am checking in the patch below to prevent a (bogus) compile time
  warning from gcc-10 when compiling the binutils on an s390 host.
  (It seems that gcc-10 for the s390 is keener at performing some
  optimizations than other platforms).  The compiler complains that a
  strncpy might leave a string buffer unterminated, whereas in fact that
  code has been written in such a way that this cannot happen.  For now
  though I am silencing the warning by adding an explicit insertion of
  the NUL byte at the end of the buffer.

Cheers
  Nick

binutils/ChangeLog
2020-02-07  Nick Clifton  <nickc@redhat.com>

	* dwarf.c (display_debug_lines_decoded): Force a NUL termination
	of the truncated file name.

Patch

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 35842f74b2..6ecfab5d5a 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -4905,6 +4905,11 @@  display_debug_lines_decoded (struct dwarf_section *  section,
 		  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.  */
+		  newFileName[MAX_FILENAME_LENGTH] = 0;
 		}
 	      else
 		{