From 5869006ce15d80c3249b5a46256987feba363ff1 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 12 Dec 2020 22:45:35 +0100 Subject: [PATCH] Replaced redundant checked with asserts Although the checks where strictly redundant, an update or restructuring of the loops/files could cause a signficant issues. For that keep them but within an assert() statement to be clear what it is about. Signed-off-by: Nikos Mavrogiannopoulos --- src/common/common.c | 7 +++++-- src/ip-util.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/common.c b/src/common/common.c index ce714652..aa942abd 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "common.h" #include "defs.h" @@ -254,7 +255,8 @@ ssize_t force_read(int sockfd, void *buf, size_t len) if (ret == -1) { if (errno != EAGAIN && errno != EINTR) return ret; - } else if (ret == 0 && left != 0) { + } else if (ret == 0) { + assert(left != 0); /* ensured by the while */ errno = ENOENT; return -1; } @@ -295,7 +297,8 @@ ssize_t force_read_timeout(int sockfd, void *buf, size_t len, unsigned sec) if (ret == -1) { if (errno != EAGAIN && errno != EINTR) return ret; - } else if (ret == 0 && left != 0) { + } else if (ret == 0) { + assert(left != 0); errno = ENOENT; return -1; } diff --git a/src/ip-util.c b/src/ip-util.c index 224a0f12..48a48bf6 100644 --- a/src/ip-util.c +++ b/src/ip-util.c @@ -21,6 +21,7 @@ #include #include #include +#include /* for inet_ntop */ #include #include @@ -218,7 +219,8 @@ char *human_addr2(const struct sockaddr *sa, socklen_t salen, if (salen == sizeof(struct sockaddr_in6)) { port = (unsigned)ntohs(((struct sockaddr_in6*)sa)->sin6_port); - if (full != 0 && port != 0 && buflen > 0) { + if (full != 0 && port != 0) { + assert(buflen > 0); /* already checked, but to avoid regression */ *buf = '['; buf++; buflen--;