sunflower-embedded-system-emulator
sunflower-embedded-system-emulator copied to clipboard
Wrong size in `snprintf` in `uncertain_upe.c`
Wrong size in snprintf in uncertain_upe.c:
uncertain_upe.c:589:49: warning: ‘%-*d’ directive output truncated writing between 5 and 11 bytes into a region of size 4 [-Wformat-truncation=]
result = snprintf(buffer, PRINT_DIGITS + 1, " u%-*d", PRINT_DIGITS, row);
^~~~
uncertain_upe.c:589:9: note: ‘snprintf’ output between 8 and 14 bytes into a destination of size 6
result = snprintf(buffer, PRINT_DIGITS + 1, " u%-*d", PRINT_DIGITS, row);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uncertain_upe.c:614:49: warning: ‘%#-*.*f’ directive output truncated writing between 7 and 316 bytes into a region of size 6 [-Wformat-truncation=]
result = snprintf(buffer, PRINT_DIGITS + 1, "%#-*.*f",
^~~~~~~
uncertain_upe.c:614:11: note: ‘snprintf’ output between 8 and 317 bytes into a destination of size 6
result = snprintf(buffer, PRINT_DIGITS + 1, "%#-*.*f",
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRINT_DIGITS, PRINT_DIGITS, var);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uncertain_upe.c:630:50: warning: ‘%#-*.*f’ directive output truncated writing between 7 and 316 bytes into a region of size 6 [-Wformat-truncation=]
result = snprintf(buffer, PRINT_DIGITS + 1, "%#-*.*f",
^~~~~~~
uncertain_upe.c:630:12: note: ‘snprintf’ output between 8 and 317 bytes into a destination of size 6
result = snprintf(buffer, PRINT_DIGITS + 1, "%#-*.*f",
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRINT_DIGITS, PRINT_DIGITS, covar);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sorry! This code is a bit of a mess from me. I tried to workout my original intention but I have no idea what I was trying to do.
Some thoughts to try and resolve my sense of responsibility for these:
-
I think the
PRINT_DIGITSconstant is meant to control how many decimal places we use when print the floating point values of variances/covariance. -
Some of the warnings are spurious as
rowmust be in the range[0, 32)but the compiler has to assume thatrowmight be2_000_000. That is not to say that we should ignore the warning but only that the solution probably isn't just to increase the padding because then we would have really long rows with whitespace that will never have any contents. -
Also I think that none of these could cause memory unsafety, because I used
snprintfand thePRINT_DIGITS + 1value I passed as the second argument is always less than the size of buffer. I think this function could print incorrect values to stdout but should segfault etc.