dankamongmen / growlight

notcurses block device manager / system installation tool
https://nick-black.com/dankwiki/index.php/Growlight
GNU General Public License v3.0
85 stars 12 forks source link

format-truncation warnings with gcc8+ #10

Closed dankamongmen closed 5 years ago

dankamongmen commented 5 years ago

While we're doing work here, let's finally handle these:

src/growlight.h:457:28: warning: '%02ju' directive output may be truncated writing between 2 and 17 bytes into a region of size between 0 and 8 [-Wformat-truncation=]
    snprintf(buf,bsize,"%ju.%02ju%c%c",val / dv,(val % dv) / ((dv + 99) / 100),
                            ^~~~~
src/growlight.h:457:23: note: directive argument in the range [0, 18014398509481982]
    snprintf(buf,bsize,"%ju.%02ju%c%c",val / dv,(val % dv) / ((dv + 99) / 100),
                       ^~~~~~~~~~~~~~~
src/growlight.h:457:4: note: 'snprintf' output between 7 and 41 bytes into a destination of size 10
    snprintf(buf,bsize,"%ju.%02ju%c%c",val / dv,(val % dv) / ((dv + 99) / 100),
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      prefixes[consumed - 1],uprefix);
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/growlight.h:457:28: warning: '%02ju' directive output may be truncated writing between 2 and 17 bytes into a region of size between 0 and 8 [-Wformat-truncation=]
    snprintf(buf,bsize,"%ju.%02ju%c%c",val / dv,(val % dv) / ((dv + 99) / 100),
                            ^~~~~
src/growlight.h:457:23: note: directive argument in the range [0, 18014398509481982]
    snprintf(buf,bsize,"%ju.%02ju%c%c",val / dv,(val % dv) / ((dv + 99) / 100),
                       ^~~~~~~~~~~~~~~
src/growlight.h:457:4: note: 'snprintf' output between 7 and 41 bytes into a destination of size 10
    snprintf(buf,bsize,"%ju.%02ju%c%c",val / dv,(val % dv) / ((dv + 99) / 100),
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      prefixes[consumed - 1],uprefix);

I think explicit length controls would suffice, and also help to document the code.

dankamongmen commented 5 years ago

Found one real bug, nice. Fixed.