From: Sebastien GODARD Date: Fri, 20 Jul 2018 07:30:23 +0000 (+0200) Subject: sadf_misc.c: Fix gcc format-truncation warning X-Git-Tag: v12.0.0~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e406e0eb149eb516c274e72e757617d745dda3c;p=sysstat sadf_misc.c: Fix gcc format-truncation warning 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 --- diff --git a/sadf_misc.c b/sadf_misc.c index 4684c78..c8f7a7b 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -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);