Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence compiler warning for strncat. #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Silence compiler warning for strncat. #77

wants to merge 1 commit into from

Conversation

ckujau
Copy link

@ckujau ckujau commented Apr 26, 2020

When compiling with newer GCC versions the following warning is emitted:


In file included from /usr/include/string.h:495,
from net.c:57:
In function ‘strncat’,
inlined from ‘read_remote.part.0’ at net.c:168:4:
/usr/include/bits/string_fortified.h:136:10: warning: ‘__builtin___strncat_chk’ output
may be truncated copying between 0 and 1023 bytes from a string of length 2047 [-Wstringop-truncation]
136 | return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Similar reports can be found on the interwebs:

This patch sheepishly attempts to follow these examples and the warning is now no
longer present. The program compiles but it may not be the right thing to do, please
verify!

net.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

-----------------------------------------------------------------------
In file included from /usr/include/string.h:495,
                 from net.c:57:
In function ‘strncat’,
    inlined from ‘read_remote.part.0’ at net.c:168:4:
/usr/include/bits/string_fortified.h:136:10: warning: ‘__builtin___strncat_chk’ output \
 may be truncated copying between 0 and 1023 bytes from a string of length 2047 [-Wstringop-truncation]
  136 |   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-----------------------------------------------------------------------

Similar reports can be found on the interwebs:

* Fix FTBFS with GCC-9 (Closes: #925677)
  https://salsa.debian.org/fcoe-team/fcoe-utils/-/blob/master/debian/patches/fix-gcc-warnings.patch

* gcc warns strncat() as terminating nul is not copied while it need not
  https://bugzilla.redhat.com/show_bug.cgi?id=1798636

This patch sheepishly attempts to follow these examples and the warning is now no
longer present. The program compiles but it may not be the right thing to do, please
verify!

 net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Signed-off-by: Christian Kujau <[email protected]>
@corecode
Copy link
Owner

I think we should use strlcat instead.

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.

2 participants