mirror of
https://github.com/nmap/nmap.git
synced 2026-02-07 05:56:34 +00:00
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
This commit is contained in:
@@ -1197,7 +1197,7 @@ static int chat_announce_disconnect(int fd)
|
||||
|
||||
n = Snprintf(buf, sizeof(buf),
|
||||
"<announce> <user%d> 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);
|
||||
|
||||
Reference in New Issue
Block a user