[SLOF] GCC compiler warning in create_crc.c
Alexey Kardashevskiy
aik at ozlabs.ru
Wed Jul 18 19:26:13 AEST 2018
On 17/7/18 9:33 pm, Thomas Huth wrote:
>
> 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?
Strangely my gcc 8.1.1 built from the sources does not throw these
errors on power7 box (and it did complain about the other bugs you
posted weeks ago), I wonder what is the difference to your gcc :-/
--
Alexey
More information about the SLOF
mailing list