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

Compiling with -Wall causes stringop-truncation error #118

Open
viking opened this issue Jul 30, 2021 · 2 comments
Open

Compiling with -Wall causes stringop-truncation error #118

viking opened this issue Jul 30, 2021 · 2 comments
Labels

Comments

@viking
Copy link

viking commented Jul 30, 2021

After running ./configure and make, here's what happened:

cc -MD -Wall -O2 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror   -DLIB_DIR=\"/usr/local/lib\" -DINSTALL_PREFIX=\"/usr/local\" -DDLL_NAME=\"libproxychains4.so\" -DSYSCONFDIR=\"/usr/local/etc\"  -fPIC -c -o src/core.o src/core.c
src/core.c: In function ‘proxy_gethostbyname’:
src/core.c:832:9: error: ‘strncpy’ specified bound 8192 equals destination size [-Werror=stringop-truncation]
  832 |         strncpy(data->addr_name, name, sizeof(data->addr_name));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/core.c: In function ‘proxy_getaddrinfo’:
src/core.c:917:17: error: ‘strncpy’ specified bound 256 equals destination size [-Werror=stringop-truncation]
  917 |                 strncpy(space->addr_name, node, sizeof(space->addr_name));
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:65: src/core.o] Error 1

Here's my gcc version:

gcc (GCC) 11.1.1 20210531 (Red Hat 11.1.1-3)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@javabeanz
Copy link

same here.
gcc version 11.2.1 20211203 (Red Hat 11.2.1-7) (GCC)

@LuomingXu
Copy link

https://stackoverflow.com/questions/50198319/gcc-8-wstringop-truncation-what-is-the-good-practice

modify src/core.c

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy(data->addr_name, name, sizeof(data->addr_name));
#pragma GCC diagnostic pop

same for strncpy(space->addr_name, node, sizeof(space->addr_name));

@haad haad added the bug label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants