diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/format.c | 5 | ||||
-rw-r--r-- | src/io.c | 3 | ||||
-rw-r--r-- | src/map.c | 2 | ||||
-rw-r--r-- | src/proc.c | 2 | ||||
-rw-r--r-- | src/socket.c | 7 | ||||
-rw-r--r-- | src/tc-socket.c | 31 | ||||
-rw-r--r-- | src/tc-string.c | 4 |
7 files changed, 48 insertions, 6 deletions
diff --git a/src/format.c b/src/format.c index 25c09d6..e924c6a 100644 --- a/src/format.c +++ b/src/format.c @@ -7,6 +7,7 @@ * General Public License as published by the Free Software Foundation; * either version 2.1 or (at your option) any later version. */ +#include <assert.h> #include <errno.h> #include <stdbool.h> #include <stddef.h> @@ -681,6 +682,7 @@ EXPORT_SYMBOL ssize_t HXformat3_aprintf(const struct HXformat_map *blk, out: ret = -errno; HXmc_free(out); + *resultp = nullptr; return ret; } @@ -716,7 +718,7 @@ EXPORT_SYMBOL int HXformat_sprintf(const struct HXformat_map *ftable, EXPORT_SYMBOL ssize_t HXformat3_sprintf(const struct HXformat_map *ftable, char *dest, size_t size, const char *fmt) { - hxmc_t *str; + hxmc_t *str = nullptr; ssize_t ret; if ((ret = HXformat_aprintf(ftable, &str, fmt)) < 0) @@ -725,6 +727,7 @@ EXPORT_SYMBOL ssize_t HXformat3_sprintf(const struct HXformat_map *ftable, *dest = '\0'; return 0; } + assert(str != nullptr); strncpy(dest, str, size); size_t xl = strlen(dest); HXmc_free(str); @@ -66,7 +66,7 @@ static int mkdir_gen(const char *d, unsigned int mode) return 1; if (errno != EEXIST) return -errno; - if (lstat(d, &sb) == 0) { + if (stat(d, &sb) == 0) { #if defined(_WIN32) if (sb.st_mode & S_IFDIR) #else @@ -424,6 +424,7 @@ HX_realpath_symres(struct HX_realpath_state *state, const char *path) return -ELOOP; #endif + assert(state->link_target != nullptr); if (*state->link_target == '/') { *state->dest = '\0'; if (HXmc_setlen(&state->dest, 0) == NULL) @@ -1145,7 +1145,7 @@ static const struct HXmap_node *HXumap_traverse(struct HXumap_trav *trav) while (trav->head == &hmap->bk_array[trav->bk_current]) { if (++trav->bk_current >= HXhash_primes[hmap->power]) - return false; + return NULL; trav->head = hmap->bk_array[trav->bk_current].next; } @@ -69,7 +69,7 @@ static int HXproc_switch_group(const struct passwd *pw, const char *group) return HXproc_switch_gid(pw, gr->gr_gid); } -EXPORT_SYMBOL int HXproc_switch_user(const char *user, const char *group) +EXPORT_SYMBOL enum HXproc_su_status HXproc_switch_user(const char *user, const char *group) { const struct passwd *pw = NULL; if (user != NULL && *user != '\0') { diff --git a/src/socket.c b/src/socket.c index 9b5d78a..0b6f674 100644 --- a/src/socket.c +++ b/src/socket.c @@ -86,8 +86,11 @@ int HX_addrport_split(const char *spec, char *host, unsigned long hlen = end - spec; if (hlen >= hbufsz) return -E2BIG; - if (*++end == '\0') + if (*++end == '\0') { + memmove(host, spec, hlen); + host[hlen] = '\0'; return 1; + } if (*end++ != ':') return -EINVAL; char *nend = nullptr; @@ -146,6 +149,8 @@ int HX_inet_connect(const char *host, uint16_t port, unsigned int oflags) struct addrinfo *aires = nullptr; int ret = HX_inet_lookup(host, port, AI_ADDRCONFIG, &aires); int saved_errno = 0; + if (ret != 0) + ; for (const struct addrinfo *r = aires; r != nullptr; r = r->ai_next) { int fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol); if (fd < 0) { diff --git a/src/tc-socket.c b/src/tc-socket.c index 9904ba8..3cdeb90 100644 --- a/src/tc-socket.c +++ b/src/tc-socket.c @@ -12,12 +12,30 @@ #ifndef AI_V4MAPPED # define AI_V4MAPPED 0 #endif +#include "internal.h" -int main(void) +static int t_parse(void) +{ + char host[32] = "bogus"; + if (HX_addrport_split("[::1]", host, sizeof(host), nullptr) != 1 || + strcmp(host, "::1") != 0) + return 1; + if (HX_addrport_split("[]", host, sizeof(host), nullptr) != 1 || + strcmp(host, "") != 0) + return 1; + if (HX_addrport_split("", host, sizeof(host), nullptr) != 1 || + strcmp(host, "") != 0) + return 1; + return 0; +} + +static int t_local(void) { static const char *addrs[] = { "::1", "::2", "::ffff:127.0.0.1", "::", + "[::1]", "[::2]", "[::ffff:127.0.0.1]", "[::]", "127.0.0.1", "127.0.0.2", "1.1.1.1", "255.255.255.255", + "[127.0.0.1]", "[127.0.0.2]", "[1.1.1.1]", "[255.255.255.255]", }; for (size_t i = 0; i < ARRAY_SIZE(addrs); ++i) { char host[32] = {}; @@ -73,3 +91,14 @@ int main(void) } return EXIT_SUCCESS; } + +int main(void) +{ + int ret = t_parse(); + if (ret != 0) + return ret; + ret = t_local(); + if (ret != EXIT_SUCCESS) + return ret; + return EXIT_SUCCESS; +} diff --git a/src/tc-string.c b/src/tc-string.c index 77235c2..9bf668b 100644 --- a/src/tc-string.c +++ b/src/tc-string.c @@ -84,12 +84,16 @@ static void t_strncat(void) { char data[5] = "DATA"; +#ifndef __clang__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" +#endif if (snprintf(data, sizeof(data), "12345678") >= static_cast(ssize_t, sizeof(data))) printf("Not enough space\n"); +#ifndef __clang__ #pragma GCC diagnostic pop +#endif printf("String: >%s<\n", data); HX_strlcat(data, "pqrstuv__", 2); |