From d36705f402989156bb7eede7ecf3d64ddcfd20a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 19 May 2023 17:34:00 +0200 Subject: [PATCH] libsmartcols: (samples): fix format truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As this is only an example and the needed memory is not much just hardcode a large enough number. The previously computed value was wrong anyways. libsmartcols/samples/continuous.c: In function 'main': libsmartcols/samples/continuous.c:110:61: error: '%3d' directive output may be truncated writing between 3 and 11 bytes into a region of size between 0 and 7 [-Werror=format-truncation=] 110 | snprintf(timecell, timecellsz, "%f [%3d%%]", diff, | ^~~ libsmartcols/samples/continuous.c:110:25: note: 'snprintf' output between 11 and 333 bytes into a destination of size 12 110 | snprintf(timecell, timecellsz, "%f [%3d%%]", diff, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 111 | done ? 100 : (int)(diff / (TIME_PERIOD / 100.0))); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libsmartcols/samples/continuous.c:110:61: error: '%3d' directive output may be truncated writing 3 bytes into a region of size between 0 and 7 [-Werror=format-truncation=] 110 | snprintf(timecell, timecellsz, "%f [%3d%%]", diff, | ^~~ libsmartcols/samples/continuous.c:110:25: note: 'snprintf' output between 11 and 325 bytes into a destination of size 12 110 | snprintf(timecell, timecellsz, "%f [%3d%%]", diff, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 111 | done ? 100 : (int)(diff / (TIME_PERIOD / 100.0))); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Thomas Weißschuh --- libsmartcols/samples/continuous.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsmartcols/samples/continuous.c b/libsmartcols/samples/continuous.c index 7db3f8464..6bdba6e82 100644 --- a/libsmartcols/samples/continuous.c +++ b/libsmartcols/samples/continuous.c @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) { struct libscols_table *tb; size_t i; - const size_t timecellsz = sizeof(stringify_value(UINT_MAX)); + const size_t timecellsz = 500; struct timeval last; scols_init_debug(0);