https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88780

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Marietto from comment #6)
...
> In function ‘strncpy’,
> inlined from ‘xc_set_cpufreq_gov’ at xc_pm.c:308:5:
> /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error:
> ‘__builtin_strncpy’ specified bound 16 equals destination size
> [-Werror=stringop-truncation]
> 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This instance of the warning is most likely unrelated to the one reported in
comment #0 (to tell for sure we'd need a test case to reproduce it).  It
indicates that strncpy is being called with the third argument set to the size
of the destination array, which leaves the destination unterminated unless the
source string is shorter.  The following articles describe the problem and the
suggested solutions in detail:

https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/
https://us-cert.cisa.gov/bsi/articles/knowledge/coding-practices/strncpy-and-strncat

Reply via email to