diff options
author | Richard Marko <srk@48.io> | 2021-02-13 13:14:08 +0300 |
---|---|---|
committer | Richard Marko <srk@48.io> | 2021-02-13 13:14:08 +0300 |
commit | 412ef4235bda09285aad9d0d5097e66366b20c28 (patch) | |
tree | 5321be50db0a42a0a0ca3d7d3118bd7d62076640 | |
parent | 148b851d10abb2dcb36cf2b952e9bca2561081d7 (diff) |
fix GCC strncpy warnings
Recent GCC added checks for this and it triggers `Werror` with
```
In function 'strncpy',
inlined from 'proxy_gethostbyname' at src/core.c:832:2:
/nix/store/hayaj8q9rc7swx4llcjqymmg3zr525lx-glibc-2.32-25-dev/include/bits/string_fortified.h:91:10: error: '__builtin_strncpy' specified bound 8192 equals destination size [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-truncation-Werror=stringop-truncation8;;]
91 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'strncpy',
inlined from 'proxy_getaddrinfo' at src/core.c:917:3:
/nix/store/hayaj8q9rc7swx4llcjqymmg3zr525lx-glibc-2.32-25-dev/include/bits/string_fortified.h:91:10: error: '__builtin_strncpy' specified bound 256 equals destination size [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-truncation-Werror=stringop-truncation8;;]
91 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
```
-rw-r--r-- | src/core.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -829,7 +829,7 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data* MUTEX_UNLOCK(&internal_ips_lock); - strncpy(data->addr_name, name, sizeof(data->addr_name)); + strncpy(data->addr_name, name, sizeof(data->addr_name) - 1); data->hostent_space.h_name = data->addr_name; data->hostent_space.h_length = sizeof(in_addr_t); @@ -914,7 +914,7 @@ int proxy_getaddrinfo(const char *node, const char *service, const struct addrin p->ai_addr = &space->sockaddr_space; if(node) - strncpy(space->addr_name, node, sizeof(space->addr_name)); + strncpy(space->addr_name, node, sizeof(space->addr_name) - 1); p->ai_canonname = space->addr_name; p->ai_next = NULL; p->ai_family = space->sockaddr_space.sa_family = AF_INET; |