]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Silence gcc-8 warnings
authorAlan Modra <amodra@gmail.com>
Mon, 23 Apr 2018 00:12:44 +0000 (09:42 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 23 Apr 2018 08:40:41 +0000 (18:10 +0930)
All of these warnings were false positives.  -Wstringop-truncation is
particularly annoying when it warns about strncpy used quite correctly.

bfd/
* elf-linux-core.h (swap_linux_prpsinfo32_ugid32_out): Disable
gcc-8 string truncation warning.
(swap_linux_prpsinfo32_ugid16_out): Likewise.
(swap_linux_prpsinfo64_ugid32_out): Likewise.
(swap_linux_prpsinfo64_ugid16_out): Likewise.
* elf.c (elfcore_write_prpsinfo): Likewise.
gas/
* stabs.c (generate_asm_file): Use memcpy rather than strncpy.
Remove call to strlen inside loop.
* config/tc-cr16.c (getreg_image): Warning fix.
* config/tc-crx.c (getreg_image): Warning fix.

bfd/ChangeLog
bfd/elf-linux-core.h
bfd/elf.c
gas/ChangeLog
gas/config/tc-cr16.c
gas/config/tc-crx.c
gas/stabs.c

index fa26810c1989c07330b883d84af8ebb7896476c5..7cc35f36e5824d7d2939ec1a825ccc375cc4115f 100644 (file)
@@ -1,3 +1,12 @@
+2018-04-23  Alan Modra  <amodra@gmail.com>
+
+       * elf-linux-core.h (swap_linux_prpsinfo32_ugid32_out): Disable
+       gcc-8 string truncation warning.
+       (swap_linux_prpsinfo32_ugid16_out): Likewise.
+       (swap_linux_prpsinfo64_ugid32_out): Likewise.
+       (swap_linux_prpsinfo64_ugid16_out): Likewise.
+       * elf.c (elfcore_write_prpsinfo): Likewise.
+
 2018-04-20  Alan Modra  <amodra@gmail.com>
 
        PR 22978
index 0a5d76fe9df1f7ae80073fc4bbbf969dbcb8d1b4..25d33f62cc642c89875a14ec74ce1e69bb2feaff 100644 (file)
@@ -69,8 +69,12 @@ swap_linux_prpsinfo32_ugid32_out
   bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
   bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
   bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
   strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
   strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
+#pragma GCC diagnostic pop
 }
 
 /* External 32-bit structure for PRPSINFO.  This structure is
@@ -121,8 +125,12 @@ swap_linux_prpsinfo32_ugid16_out
   bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
   bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
   bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
   strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
   strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
+#pragma GCC diagnostic pop
 }
 
 /* External 64-bit structure for PRPSINFO.  This structure is
@@ -174,8 +182,12 @@ swap_linux_prpsinfo64_ugid32_out
   bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
   bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
   bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
   strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
   strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
+#pragma GCC diagnostic pop
 }
 
 /* External 64-bit structure for PRPSINFO.  This structure is
@@ -227,8 +239,12 @@ swap_linux_prpsinfo64_ugid16_out
   bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
   bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
   bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
   strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
   strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
+#pragma GCC diagnostic pop
 }
 
 #endif
index 8ea5a81cbe36020d4bc2fc8b880ca83282c5349f..b4549ea7173543c93e44dbba3cd50ad7fd8a4f1c 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -10549,8 +10549,12 @@ elfcore_write_prpsinfo (bfd  *abfd,
 #endif
 
       memset (&data, 0, sizeof (data));
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
       strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
       strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
+#pragma GCC diagnostic pop
       return elfcore_write_note (abfd, buf, bufsiz,
                                 "CORE", note_type, &data, sizeof (data));
     }
index 21d09f8e2c62f4772e16b27b848dd7f89ac6f67d..ba3d8b5d031e1e83c8710c8d9bfb15e24d93072b 100644 (file)
@@ -1,3 +1,10 @@
+2018-04-23  Alan Modra  <amodra@gmail.com>
+
+       * stabs.c (generate_asm_file): Use memcpy rather than strncpy.
+       Remove call to strlen inside loop.
+       * config/tc-cr16.c (getreg_image): Warning fix.
+       * config/tc-crx.c (getreg_image): Warning fix.
+
 2018-04-20  Kito Cheng  <kito.cheng@gmail.com>
 
        * config/tc-riscv.c (options): Add OPTION_RELAX and
index 0b73003c4e0153cb88c7a0a7c8f950afbb0f4bdd..d25afccb1bc025549422f426f5182c25c681f771 100644 (file)
@@ -1124,8 +1124,7 @@ getreg_image (reg r)
 /* Issue a error message when register is illegal.  */
 #define IMAGE_ERR \
   as_bad (_("Illegal register (`%s') in Instruction: `%s'"), \
-            reg_name, ins_parse);                            \
-  break;
+         reg_name, ins_parse);
 
   switch (rreg->type)
     {
@@ -1134,6 +1133,7 @@ getreg_image (reg r)
         return rreg->image;
       else
         IMAGE_ERR;
+      break;
 
     case CR16_P_REGTYPE:
       return rreg->image;
@@ -1141,6 +1141,7 @@ getreg_image (reg r)
 
     default:
       IMAGE_ERR;
+      break;
     }
 
   return 0;
index ce8cbcece26981ed51283c1fe980d5d6667c2834..8cf4af44b6ac152f148970fe465cf7d94eea6cd4 100644 (file)
@@ -1135,8 +1135,7 @@ getreg_image (reg r)
 /* Issue a error message when register is illegal.  */
 #define IMAGE_ERR \
   as_bad (_("Illegal register (`%s') in instruction: `%s'"), \
-           reg_name, ins_parse);                            \
-  break;
+         reg_name, ins_parse);
 
   switch (rreg->type)
   {
@@ -1145,18 +1144,21 @@ getreg_image (reg r)
        return rreg->image;
       else
        IMAGE_ERR;
+      break;
 
     case CRX_CFG_REGTYPE:
       if (is_procreg)
        return rreg->image;
       else
        IMAGE_ERR;
+      break;
 
     case CRX_R_REGTYPE:
       if (! is_procreg)
        return rreg->image;
       else
        IMAGE_ERR;
+      break;
 
     case CRX_C_REGTYPE:
     case CRX_CS_REGTYPE:
@@ -1165,6 +1167,7 @@ getreg_image (reg r)
 
     default:
       IMAGE_ERR;
+      break;
   }
 
   return 0;
index d82de3154331151d14f471e6cf71f99d71e1de6b..6ddbdada15c3d4c7bf2fccbf8ca5e06eba10e662 100644 (file)
@@ -543,12 +543,12 @@ generate_asm_file (int type, const char *file)
   while (tmp < file_endp)
     {
       const char *bslash = strchr (tmp, '\\');
-      size_t len = (bslash) ? (size_t) (bslash - tmp + 1) : strlen (tmp);
+      size_t len = bslash != NULL ? bslash - tmp + 1 : file_endp - tmp;
 
       /* Double all backslashes, since demand_copy_C_string (used by
         s_stab to extract the part in quotes) will try to replace them as
         escape sequences.  backslash may appear in a filespec.  */
-      strncpy (bufp, tmp, len);
+      memcpy (bufp, tmp, len);
 
       tmp += len;
       bufp += len;