From 75318985a1de829436908f80cfef1a8d8d8c8b84 Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 14 Sep 2020 17:41:39 +0000 Subject: [PATCH] Silence static analysis warning LGTM points out that since comparison with sizeof(buf) coerces n to unsigned, all negative values become very large values, which are necessarily larger than sizeof(buf), so the test is redundant. We still want the test in our code to be explicit that we are checking for it, so reordering the comparisons should silence the warning. A good optimizing compiler should be able to combine the two conditions anyway. See https://github.com/github/codeql/issues/4249 --- ncat/ncat_listen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index 4f585102e..494e66376 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -1197,7 +1197,7 @@ static int chat_announce_disconnect(int fd) n = Snprintf(buf, sizeof(buf), " is disconnected.\n", fd); - if (n >= sizeof(buf) || n < 0) + if (n < 0 || n >= sizeof(buf)) return -1; return ncat_broadcast(&master_broadcastfds, &broadcast_fdlist, buf, n);