Skip to content

Conversation

tbarbette
Copy link
Contributor

Recent GCC (9.3 at least) got smarter and sees that strncopy should not
be used with the length of the string, and memcpy should be used instead. The
error:

In function strncpy,
inlined from LoadConfig at ../common/applib.c:127:4:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: __builtin_strncpy output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../common/applib.c: In function LoadConfig:
../common/applib.c:124:15: note: length computed here
124 | if ((len = strlen(p)) > CONF_VALUE_LEN)

Recent GCC (9.3 at least) got smarter and sees that strncopy should not
be used with its own length, and memcpy should be used instead. The
error:

In function strncpy,
    inlined from LoadConfig at ../common/applib.c:127:4:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: __builtin_strncpy output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../common/applib.c: In function LoadConfig:
../common/applib.c:124:15: note: length computed here
  124 |    if ((len = strlen(p)) > CONF_VALUE_LEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant