]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: (samples): fix format truncation warning
authorThomas Weißschuh <thomas@t-8ch.de>
Fri, 19 May 2023 15:34:00 +0000 (17:34 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Fri, 19 May 2023 15:50:01 +0000 (17:50 +0200)
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 <thomas@t-8ch.de>
libsmartcols/samples/continuous.c

index 7db3f8464d810b76041f600823107f24ffac6b90..6bdba6e824003a5553b89a009ba1f1c27d86bb78 100644 (file)
@@ -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);