Bugzilla – Bug 831
workaround for spurious fread_chk warning against petal.c
Last modified: 2016-09-09 07:55:43 CEST
Created attachment 356 [details]
If I build unbound using my gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2), it results in the following warning for testcode/petal.c:
In function ‘__fread_alias’,
inlined from ‘provide_file_chunked’ at testcode/petal.c:476:49,
inlined from ‘service_ssl’ at testcode/petal.c:551:7:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:290:9: warning: call to ‘__fread_chk_warn’ declared with attribute warning: fread called with bigger size * nmemb than length of destination buffer
return __fread_chk (__ptr, __bos0 (__ptr), __size, __n, __stream);
As far as I can see this is a false positive, but from a quick look __fread_chk() doesn't seem to like to have a variable read size unrelated to the buffer size and complains about it.
Unfortunately this makes it impossible to build unbound with -Werror. The attached patch will prevent the warning (and it should still be safe), although admittedly it's less efficient and unnecessarily complicated except for silencing a broken compiler. Alternatively you could define tmpbuf as "char tmpbuf[avail-16]", which is simpler but relies on variable-length arrays.
I'd understand it if you consider it an unnecessary hack, but it would make my life much easier if you could adopt some workaround for this, whether it's the attached patch or not.
Applied the patch. Thank you for reporting it!
Best regards, Wouter