NOAA-EMC / NCEPLIBS-bufr

The NCEPLIBS-bufr library contains routines and utilites for working with the WMO BUFR format.
Other
44 stars 19 forks source link

warnings for C code even when -Wall is not used... #325

Closed edwardhartnett closed 1 year ago

edwardhartnett commented 1 year ago
/home/ed/NCEPLIBS-bufr/utils/xbfmg.c: In function ‘main’:
/home/ed/NCEPLIBS-bufr/utils/xbfmg.c:222:35: warning: ‘%06lu’ directive writing between 6 and 20 bytes into a region of size between 0 and 124 [-Wformat-overflow=]
  222 |             sprintf( outfile, "%s.%06lu", outfile_temp, ++noutfile );
      |                                   ^~~~~
/home/ed/NCEPLIBS-bufr/utils/xbfmg.c:222:31: note: using the range [0, 18446744073709551615] for directive argument
  222 |             sprintf( outfile, "%s.%06lu", outfile_temp, ++noutfile );
      |                               ^~~~~~~~~~
In file included from /usr/include/stdio.h:867,
                 from /home/ed/NCEPLIBS-bufr/utils/xbfmg.c:7:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 8 and 146 bytes into a destination of size 125
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 75%] Linking C executable xbfmg

and

/home/ed/NCEPLIBS-bufr/b/utils/debufr.c: In function ‘main’:
/home/ed/NCEPLIBS-bufr/b/utils/debufr.c:276:35: warning: ‘%s’ directive writing up to 499 bytes into a region of size between 50 and 549 [-Wformat-overflow=]
  276 |             sprintf( tblfil, "%s%c%s", tbldir, '/', wkstr );
      |                                   ^~                ~~~~~
In file included from /usr/include/stdio.h:867,
                 from /home/ed/NCEPLIBS-bufr/b/utils/debufr.c:9:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 2 and 1000 bytes into a destination of size 550
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 76%] Linking C executable debufr

NCO requires that with default flags, codes build without warning.

We intend to go one better than that, and make sure code builds with no warnings for -Wall.

But these warnings show up without even specifying -Wall...