From fe89c7df3961e72cf7f65d7ba207c987c15d1ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9?= Date: Mon, 16 Mar 2026 20:49:26 -0500 Subject: [PATCH] inet: prefer sizeof with parenthesis (#4789) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not precisely a strict rule, but this syntax is reinforced in many large C projects like the Linux kernel and cURL. Signed-off-by: Juan José Arboleda --- src/inet.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/inet.c b/src/inet.c index 620be5a35..9e812dfb1 100644 --- a/src/inet.c +++ b/src/inet.c @@ -77,7 +77,7 @@ static int inet_ntop6(const unsigned char *src, char *dst, size_t size) { * Copy the input (bytewise) array into a wordwise array. * Find the longest run of 0x00's in src[] for :: shorthanding. */ - memset(words, '\0', sizeof words); + memset(words, '\0', sizeof(words)); for (i = 0; i < (int) sizeof(struct in6_addr); i++) words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); best.base = -1; @@ -124,13 +124,13 @@ static int inet_ntop6(const unsigned char *src, char *dst, size_t size) { if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 7 && words[7] != 0x0001) || (best.len == 5 && words[5] == 0xffff))) { - int err = inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)); + int err = inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp)); if (err) return err; tp += strlen(tp); break; } - tp += snprintf(tp, sizeof tmp - (tp - tmp), "%x", words[i]); + tp += snprintf(tp, sizeof(tmp) - (tp - tmp), "%x", words[i]); } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && (best.base + best.len) == ARRAY_SIZE(words)) @@ -219,8 +219,8 @@ static int inet_pton6(const char *src, unsigned char *dst) { int ch, seen_xdigits; unsigned int val; - memset((tp = tmp), '\0', sizeof tmp); - endp = tp + sizeof tmp; + memset((tp = tmp), '\0', sizeof(tmp)); + endp = tp + sizeof(tmp); colonp = NULL; /* Leading :: requires some special handling. */ if (*src == ':') @@ -293,6 +293,6 @@ static int inet_pton6(const char *src, unsigned char *dst) { } if (tp != endp) return UV_EINVAL; - memcpy(dst, tmp, sizeof tmp); + memcpy(dst, tmp, sizeof(tmp)); return 0; }