[SLOF] GCC compiler warning in create_crc.c

Thomas Huth thuth at redhat.com
Tue Jul 17 21:33:42 AEST 2018


 Hi all,

when compiling SLOF with GCC 8.1, I currently get these compiler warnings:

create_crc.c: In function ‘createHeaderImage’:
create_crc.c:110:2: warning: ‘strncpy’ output truncated before
terminating nul copying 8 bytes from a string of the same length
[-Wstringop-truncation]
  strncpy(uHeader.stHeader.magic, FLASHFS_MAGIC, 8);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
create_crc.c:86:3: warning: ‘strncpy’ specified bound 16 equals
destination size [-Wstringop-truncation]
   strncpy(uHeader.stHeader.version, pcVersion, 16);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
create_crc.c:84:3: warning: ‘strncpy’ specified bound 16 equals
destination size [-Wstringop-truncation]
   strncpy(uHeader.stHeader.version, pcVersion, 16);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As far as I can see, the code is prefectly fine, since the fields in the
header do not have to be NUL-terminated here. Still, it's annoying to
see a compiler warning here every time you re-compile SLOF.

Does anybody have a good suggestion how to silence these? Simply use
"-Wno-stringop-truncation" for compiling that file? ... but then we
first have to check whether the compiler supports that flag, and that's
also kind of ugly. Or should we rework the code? ... that's certainly
possible, but in this case, it sounds so unnecessary...

I really don't have a suggestion for a really nice clean solution
here... anybody else got a good idea?

 Thomas


More information about the SLOF mailing list