]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Squelch some warnings.
authorGuy Harris <[email protected]>
Mon, 25 May 2020 09:02:34 +0000 (02:02 -0700)
committerGuy Harris <[email protected]>
Mon, 25 May 2020 09:02:34 +0000 (02:02 -0700)
Use ND_BYTES_AVAILABLE_AFTER() to calculate the number of bytes
remaining in the packet after a given pointer, rather than doing the
subtraction directly; that casts the result to a u_int (we don't handle
packets bigger than the maximum u_int value, so the difference between
the pointers will never be bigger than that value), so we don't have to
deal with it being a 64-bit value on LP64 or LLP64 systems.  (It also
makes it a bit clearer what we're doing).

Clean up some indentation while we're at it.

print-ppp.c
print-smb.c
print-zeromq.c
util-print.c

index 6156e19536e561836a9525c68629bedad167220e..dbd5283a947cd92ef194c304b803622f1ed4c9f7 100644 (file)
@@ -1413,7 +1413,7 @@ static void
 ppp_hdlc(netdissect_options *ndo,
          const u_char *p, u_int length)
 {
-       u_int caplen = ndo->ndo_snapend - p;
+       u_int caplen = ND_BYTES_AVAILABLE_AFTER(p);
        u_char *b, *t, c;
        const u_char *s;
        u_int i, proto;
index 402bb71f0c7cd5051d6c0b9103c5e0abb8d2378e..38a6a433ce08200ee1c68ce2ff57e786d7daf637 100644 (file)
@@ -952,7 +952,7 @@ nbt_tcp_print(netdissect_options *ndo,
        goto trunc;
     if (ndo->ndo_snapend < data)
        goto trunc;
-    caplen = ndo->ndo_snapend - data;
+    caplen = ND_BYTES_AVAILABLE_AFTER(data);
     if (caplen < 4)
        goto trunc;
     maxbuf = data + caplen;
@@ -1269,7 +1269,7 @@ smb_tcp_print(netdissect_options *ndo,
        goto trunc;
     if (ndo->ndo_snapend < data)
        goto trunc;
-    caplen = ndo->ndo_snapend - data;
+    caplen = ND_BYTES_AVAILABLE_AFTER(data);
     if (caplen < 4)
        goto trunc;
     maxbuf = data + caplen;
index ac61056a8db6418b58e93556d1b590dda38a80ce..31d699689584ddae5ab9508d15e6a4d83a1f6797 100644 (file)
@@ -169,13 +169,13 @@ static const u_char *
 zmtp1_print_intermediate_part(netdissect_options *ndo, const u_char *cp, const u_int len)
 {
        u_int frame_offset;
-       uint64_t remaining_len;
+       u_int remaining_len;
 
        ND_TCHECK_2(cp);
        frame_offset = GET_BE_U_2(cp);
        ND_PRINT("\n\t frame offset 0x%04x", frame_offset);
        cp += 2;
-       remaining_len = ndo->ndo_snapend - cp; /* without the frame length */
+       remaining_len = ND_BYTES_AVAILABLE_AFTER(cp); /* without the frame length */
 
        if (frame_offset == 0xFFFF)
                frame_offset = len - 2; /* always within the declared length */
@@ -188,14 +188,14 @@ zmtp1_print_intermediate_part(netdissect_options *ndo, const u_char *cp, const u
        if (frame_offset) {
                ND_PRINT("\n\t frame intermediate part, %u bytes", frame_offset);
                if (frame_offset > remaining_len)
-                       ND_PRINT(" (%"PRIu64" captured)", remaining_len);
+                       ND_PRINT(" (%u captured)", remaining_len);
                if (ndo->ndo_vflag) {
-                       uint64_t len_printed = min(frame_offset, remaining_len);
+                       u_int len_printed = min(frame_offset, remaining_len);
 
                        if (ndo->ndo_vflag == 1)
                                len_printed = min(VBYTES, len_printed);
                        if (len_printed > 1) {
-                               ND_PRINT(", first %"PRIu64" byte(s):", len_printed);
+                               ND_PRINT(", first %u byte(s):", len_printed);
                                hex_and_ascii_print(ndo, "\n\t ", cp, len_printed);
                        }
                }
index 8806b47599c0c2723cbbbcfaead54ce262074cda..c87e32653e4d575d3e6ab456cfdb7e5bdd8a91cc 100644 (file)
@@ -475,19 +475,22 @@ void nd_print_invalid(netdissect_options *ndo)
 int
 print_unknown_data(netdissect_options *ndo, const u_char *cp,const char *ident,int len)
 {
+       u_int len_to_print;
+
        if (len < 0) {
-          ND_PRINT("%sDissector error: print_unknown_data called with negative length",
+               ND_PRINT("%sDissector error: print_unknown_data called with negative length",
                    ident);
                return(0);
        }
-       if (ndo->ndo_snapend - cp < len)
-               len = ndo->ndo_snapend - cp;
-       if (len < 0) {
-          ND_PRINT("%sDissector error: print_unknown_data called with pointer past end of packet",
+       len_to_print = len;
+       if (ndo->ndo_snapend < cp) {
+               ND_PRINT("%sDissector error: print_unknown_data called with pointer past end of packet",
                    ident);
                return(0);
        }
-        hex_print(ndo, ident,cp,len);
+       if (ND_BYTES_AVAILABLE_AFTER(cp) < len_to_print)
+               len_to_print = ND_BYTES_AVAILABLE_AFTER(cp);
+       hex_print(ndo, ident, cp, len_to_print);
        return(1); /* everything is ok */
 }