LISP: don't decrement count variables unless we know they're not zero.
authorGuy Harris <gharris@sonic.net>
Tue, 16 Nov 2021 00:44:46 +0000 (16:44 -0800)
committerGuy Harris <gharris@sonic.net>
Tue, 16 Nov 2021 00:44:46 +0000 (16:44 -0800)
This fixes some undefined behavior warnings.

print-lisp.c

index 0012e06eea15b09290ab368dc149555fd2a334a7..756fff0ffc5a7392eed749b7ffea684636b9cc86 100644 (file)
@@ -283,8 +283,8 @@ lisp_print(netdissect_options *ndo, const u_char *bp, u_int length)
                goto invalid;
 
        /* Print all the EID records */
-       while ((length > packet_offset) && (record_count--)) {
-
+       while ((length > packet_offset) && (record_count != 0)) {
+               record_count--;
                ND_TCHECK_LEN(packet_iterator + packet_offset,
                              MAP_REGISTER_EID_LEN);
                ND_PRINT("\n");
@@ -326,7 +326,8 @@ lisp_print(netdissect_options *ndo, const u_char *bp, u_int length)
 
                ND_PRINT(" %u locator(s)", loc_count);
 
-               while (loc_count--) {
+               while (loc_count != 0) {
+                       loc_count--;
                        ND_TCHECK_LEN(packet_iterator + packet_offset,
                                      MAP_REGISTER_LOC_LEN);
                        lisp_loc = (const lisp_map_register_loc *) (packet_iterator + packet_offset);