Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong size in snprintf in uncertain_upe.c #171

Open
phillipstanleymarbell opened this issue Apr 19, 2020 · 1 comment
Open

Wrong size in snprintf in uncertain_upe.c #171

phillipstanleymarbell opened this issue Apr 19, 2020 · 1 comment
Assignees

Comments

@phillipstanleymarbell
Copy link
Member

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);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@harrysarson
Copy link
Contributor

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_DIGITS constant 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 row must be in the range [0, 32) but the compiler has to assume that row might be 2_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 snprintf and the PRINT_DIGITS + 1 value 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants