[SLOF] GCC compiler warning in create_crc.c

Thomas Huth thuth at redhat.com
Wed Jul 18 19:59:15 AEST 2018


On 18.07.2018 11:26, Alexey Kardashevskiy wrote:
> 
> 
> 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 :-/

No clue, I am also using 8.1.1 ... did you do a "make distclean"
inbetween to make sure that the romfs tool is really rebuilt?

 Thomas


More information about the SLOF mailing list