File: fix-stringop-truncation-warning.patch

package info (click to toggle)
xtrs 4.9d-3
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 5,484 kB
  • sloc: ansic: 72,545; makefile: 1,633; sh: 554; csh: 132
file content (32 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Fix stringop-truncation warning from GCC 8.

* Issue warning diagnostic if the argument to -p is too long.
* Swap order of space-padding strncat and forced setting of pdsbuf[8] to
  a null byte.  This persuades GCC that we're ensuring pdsbuf has a
  string terminator.
* Use '\0' instead of '\000' as null character escape.

cmddump.c:78:7: warning: ‘strncat’ output truncated copying between 0
and 8 bytes from a string of length 8 [-Wstringop-truncation]
       strncat(pdsbuf, "        ", 8 - strlen(pdsbuf));
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

G. Branden Robinson <g.branden.robinson@gmail.com>

--- a/cmddump.c
+++ b/cmddump.c
@@ -73,9 +73,12 @@
       isam = strtol(optarg, NULL, 0);
       break;
     case 'p':
+      if (strlen(optarg) > 8) {
+        fprintf(stderr, "warning: truncating -p argument to 8 bytes\n");
+      }
       strncpy(pdsbuf, optarg, 8);
-      pdsbuf[8] = '\000';
-      strncat(pdsbuf, "        ", 8 - strlen(pdsbuf));
+      strncat(pdsbuf, "        " /* 8 spaces */, 8 - strlen(pdsbuf));
+      pdsbuf[8] = '\0';
       pds = pdsbuf;
       break;
     case 'x':