]> granicus.if.org Git - sysstat/commitdiff
sadf_misc.c: Fix gcc format-truncation warning
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 20 Jul 2018 07:30:23 +0000 (09:30 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 20 Jul 2018 07:30:23 +0000 (09:30 +0200)
Resize buffers to avoid warnings from gcc:

sadf_misc.c: In function ‘print_dbppc_timestamp’:
sadf_misc.c:486:28: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
   snprintf(temp, 80, "%s%s ", pre, cur_date);
                            ^
sadf_misc.c:486:3: note: ‘snprintf’ output 2 or more bytes (assuming 81) into a destination of size 80
   snprintf(temp, 80, "%s%s ", pre, cur_date);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sadf_misc.c:491:25: warning: ‘%s’ directive output may be truncated writing up to 4 bytes into a region of size between 1 and 80 [-Wformat-truncation=]
  snprintf(pre, 80, "%s%s%s", temp, cur_time,
                         ^~
sadf_misc.c:491:2: note: ‘snprintf’ output 1 or more bytes (assuming 84) into a destination of size 80
  snprintf(pre, 80, "%s%s%s", temp, cur_time,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    strlen(cur_date) && utc ? " UTC" : "");
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sadf_misc.c

index 4684c787b375566fc1a4f64ec35400dc8f90cd6e..c8f7a7be5e6f3688377f706ea962ad1e0711bf2c 100644 (file)
@@ -476,21 +476,21 @@ char *print_dbppc_timestamp(int fmt, struct file_header *file_hdr, char *cur_dat
                            char *cur_time, int utc, unsigned long long itv)
 {
        int isdb = (fmt == F_DB_OUTPUT);
-       static char pre[80];
-       char temp[80];
+       static char pre[512];
+       char temp1[128], temp2[256];
 
        /* This substring appears on every output line, preformat it here */
-       snprintf(pre, 80, "%s%s%lld%s",
+       snprintf(temp1, sizeof(temp1), "%s%s%lld%s",
                 file_hdr->sa_nodename, seps[isdb], itv, seps[isdb]);
        if (strlen(cur_date)) {
-               snprintf(temp, 80, "%s%s ", pre, cur_date);
+               snprintf(temp2, sizeof(temp2), "%s%s ", temp1, cur_date);
        }
        else {
-               strcpy(temp, pre);
+               strcpy(temp2, temp1);
        }
-       snprintf(pre, 80, "%s%s%s", temp, cur_time,
+       snprintf(pre, sizeof(pre), "%s%s%s", temp2, cur_time,
                 strlen(cur_date) && utc ? " UTC" : "");
-       pre[79] = '\0';
+       pre[sizeof(pre) - 1] = '\0';
 
        if (DISPLAY_HORIZONTALLY(flags)) {
                printf("%s", pre);