[PATCH 5/5] udp.c: Add explicit cast to muffle bogus Clang warning.
Ian Jackson
ijackson at chiark.greenend.org.uk
Sat Sep 21 11:06:54 BST 2019
Mark Wooding writes ("[PATCH 5/5] udp.c: Add explicit cast to muffle bogus Clang warning."):
> Clang is complaining (`-Wsign-compare') about the comparison between
> `salen' (`socklen_t', i.e., an `int' with a false moustache) and
> `size_t' (`unsigned int' in this case). I can see that some warnings of
> this kind are useful, but not this one. The usual arithmetic
> conversions apply, so `salen' is converted to `size_t'. If it was
> negative before, it's now very positive, which will trip the the
> comparison and call `FAIL' -- which seems like a plausible outcome.
>
> Muffle the warning by adding an explicit cast. This is ugly and
> pointless, though: other suggestions are welcome.
I don't have a better idea, but I have added a comment.
Ian.
>From 1e6a0c62f6734a6cf1a9e73d11acd69b3d96b10e Mon Sep 17 00:00:00 2001
From: Ian Jackson <ijackson at chiark.greenend.org.uk>
Date: Sat, 21 Sep 2019 11:05:21 +0100
Subject: [PATCH] udp.c: Add a comment about the salen cast
Signed-off-by: Ian Jackson <ijackson at chiark.greenend.org.uk>
---
udp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/udp.c b/udp.c
index ee38d51..0d945ac 100644
--- a/udp.c
+++ b/udp.c
@@ -269,7 +269,8 @@ static bool_t record_socket_gotaddr(struct udpcommon *uc, struct udpsock *us,
socklen_t salen=sizeof(us->addr);
int r=getsockname(us->fd,&us->addr.sa,&salen);
if (r) FAIL("getsockname()");
- if ((size_t)salen>sizeof(us->addr)) { errno=0; FAIL("getsockname() length"); }
+ if ((size_t)salen>sizeof(us->addr)) /* cast squashes clang warning */
+ { errno=0; FAIL("getsockname() length"); }
return True;
failed:
--
2.11.0
More information about the sgo-software-discuss
mailing list