]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Don't decrement an unsigned zero value below zero.
authorGuy Harris <[email protected]>
Thu, 1 Feb 2018 22:16:11 +0000 (14:16 -0800)
committerGuy Harris <[email protected]>
Thu, 1 Feb 2018 22:16:11 +0000 (14:16 -0800)
In fact, don't waste time incrementing the pointer or decrementing the
count until we know that we're going to go through another trip through
the loop.  (This isn't a PDP-11 and probably isn't a VAX or 68k, so *p++
isn't going to be done by an addressing mode.)

This should fix an undefined-behavior warning.

print-isakmp.c

index ba12f912d0998205b8cb578f2f84d9887d1c10f4..af7e7b654f0f860802d318ee46c3048d44260173 100644 (file)
@@ -741,9 +741,11 @@ static const char *etypestr[] = {
 static int
 iszero(const u_char *p, size_t l)
 {
-       while (l--) {
-               if (*p++)
+       while (l != 0) {
+               if (*p)
                        return 0;
+               p++;
+               l--;
        }
        return 1;
 }