]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Squelch more narrowing warnings.
authorGuy Harris <[email protected]>
Thu, 18 Apr 2019 18:01:55 +0000 (11:01 -0700)
committerGuy Harris <[email protected]>
Thu, 18 Apr 2019 18:01:55 +0000 (11:01 -0700)
Add an ND_BYTES_BETWEEN() macro that computes how many bytes are
present, starting at the second argument and running up to (but not
including) the first argument, and returns that as a u_int (cutting it
to 32 bits on LP64 and LLP64 platforms).

Use that, including using it as a replacement for SMB's PTR_DIFF().

netdissect.h
print-bgp.c
print-lwres.c
print-resp.c
print-smb.c
smb.h
smbutil.c

index 3feeb4667db4c0bd939ff6ce2bc29f55fd1b9454..7decd4c0c4d4dd6b3f5147a57c9a7ece51842c6f 100644 (file)
@@ -356,11 +356,16 @@ extern void nd_pop_all_buffers(netdissect_options *);
 /* Bail out if "*(p)" was not captured */
 #define ND_TCHECK_SIZE(p) ND_TCHECK_LEN(p, sizeof(*(p)))
 
+/*
+ * Number of bytes between two pointers.
+ */
+#define ND_BYTES_BETWEEN(p1, p2) ((u_int)(((const uint8_t *)(p1)) - (const uint8_t *)(p2)))
+
 /*
  * Number of bytes remaining in the captured data, starting at the
  * byte pointed to by the argument.
  */
-#define ND_BYTES_AVAILABLE_AFTER(p) ((u_int)(ndo->ndo_snapend - (p)))
+#define ND_BYTES_AVAILABLE_AFTER(p) ND_BYTES_BETWEEN(ndo->ndo_snapend, (p))
 
 #define ND_PRINT(...) (ndo->ndo_printf)(ndo, __VA_ARGS__)
 #define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length)
index dbbf7721098731d7b2ca7e565da3886fd5f3e737..cfebaf221ce0a9015a8e2b5a1529819e356d66fb 100644 (file)
@@ -1925,8 +1925,8 @@ bgp_attr_print(netdissect_options *ndo,
             ND_PRINT(", no SNPA");
         }
 
-        add_path4 = check_add_path(ndo, tptr, (len-(tptr - pptr)), 32);
-        add_path6 = check_add_path(ndo, tptr, (len-(tptr - pptr)), 128);
+        add_path4 = check_add_path(ndo, tptr, (len-ND_BYTES_BETWEEN(tptr, pptr)), 32);
+        add_path6 = check_add_path(ndo, tptr, (len-ND_BYTES_BETWEEN(tptr, pptr)), 128);
 
         while (tptr < pptr + len) {
             switch (af<<8 | safi) {
@@ -2106,8 +2106,8 @@ bgp_attr_print(netdissect_options *ndo,
 
         tptr += 3;
 
-        add_path4 = check_add_path(ndo, tptr, (len-(tptr - pptr)), 32);
-        add_path6 = check_add_path(ndo, tptr, (len-(tptr - pptr)), 128);
+        add_path4 = check_add_path(ndo, tptr, (len-ND_BYTES_BETWEEN(tptr, pptr)), 32);
+        add_path6 = check_add_path(ndo, tptr, (len-ND_BYTES_BETWEEN(tptr, pptr)), 128);
 
         while (tptr < pptr + len) {
             switch (af<<8 | safi) {
index 0d2cbb4b9a88af3f67400deed6519851079e6ac6..6f7d9aaae795fef780e11a6b3b112fc136c3f23f 100644 (file)
@@ -210,7 +210,7 @@ lwres_printname(netdissect_options *ndo,
        }
        p++;    /* skip terminating \0 */
 
-       return (int)(p - p0);
+       return ND_BYTES_BETWEEN(p, p0);
 
   trunc:
        return -1;
@@ -254,7 +254,7 @@ lwres_printbinlen(netdissect_options *ndo,
                ND_PRINT("%02x", GET_U_1(p));
                p++;
        }
-       return (int)(p - p0);
+       return ND_BYTES_BETWEEN(p, p0);
 
   trunc:
        return -1;
@@ -297,7 +297,7 @@ lwres_printaddr(netdissect_options *ndo,
                }
        }
 
-       return p - p0;
+       return ND_BYTES_BETWEEN(p, p0);
 
   trunc:
        return -1;
index beeec1ce184f13e1e1c5b742bd02f4532421f17d..b94366854161fa0a1730448ef1f7091bdee36e95 100644 (file)
@@ -311,7 +311,7 @@ resp_print_string_error_integer(netdissect_options *ndo, const u_char *bp, int l
      * preceding the \r\n.  That includes the opcode, so don't print
      * that.
      */
-    len = (bp_ptr - bp);
+    len = ND_BYTES_BETWEEN(bp_ptr, bp);
     RESP_PRINT_SEGMENT(ndo, bp, len);
     ret_len = 1 /*<opcode>*/ + len /*<string>*/ + 2 /*<CRLF>*/;
 
@@ -436,7 +436,7 @@ resp_print_inline(netdissect_options *ndo, const u_char *bp, int length) {
      * Found it; bp_ptr points to the \r or \n, so bp_ptr - bp is the
      * Length of the line text that precedes it.  Print it.
      */
-    len = (bp_ptr - bp);
+    len = ND_BYTES_BETWEEN(bp_ptr, bp);
     RESP_PRINT_SEGMENT(ndo, bp, len);
 
     /*
index d12779d8a19bb7aebb2afde43412af9f1dde3589..961ef643cf3f6e70025ec1170b2e44201a308e5c 100644 (file)
@@ -419,7 +419,7 @@ print_negprot(netdissect_options *ndo,
        smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
            unicodestr);
     else
-       smb_data_print(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
+       smb_data_print(ndo, words + 1, min(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1)));
 
     ND_TCHECK_2(data);
     bcc = GET_LE_U_2(data);
@@ -430,7 +430,7 @@ print_negprot(netdissect_options *ndo,
                                              maxbuf), unicodestr);
        else
            smb_data_print(ndo, data + 2,
-                           min(GET_LE_U_2(data), PTR_DIFF(maxbuf, data + 2)));
+                           min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -464,7 +464,7 @@ print_sesssetup(netdissect_options *ndo,
        smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
            unicodestr);
     else
-       smb_data_print(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
+       smb_data_print(ndo, words + 1, min(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1)));
 
     ND_TCHECK_2(data);
     bcc = GET_LE_U_2(data);
@@ -475,7 +475,7 @@ print_sesssetup(netdissect_options *ndo,
                                              maxbuf), unicodestr);
        else
            smb_data_print(ndo, data + 2,
-                           min(GET_LE_U_2(data), PTR_DIFF(maxbuf, data + 2)));
+                           min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -516,7 +516,7 @@ print_lockingandx(netdissect_options *ndo,
                                              maxbuf), unicodestr);
        else
            smb_data_print(ndo, data + 2,
-                           min(GET_LE_U_2(data), PTR_DIFF(maxbuf, data + 2)));
+                           min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -892,7 +892,7 @@ print_smb(netdissect_options *ndo,
            } else {
                if (bcc > 0) {
                    ND_PRINT("smb_buf[]=\n");
-                   smb_data_print(ndo, data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2)));
+                   smb_data_print(ndo, data + 2, min(bcc, ND_BYTES_BETWEEN(maxbuf, data + 2)));
                }
            }
        }
diff --git a/smb.h b/smb.h
index d3bda569376f10624bf53c7ed37297b967c8836e..d49c192f7aba77471d7e72de2da358726a8c6fac 100644 (file)
--- a/smb.h
+++ b/smb.h
 #define TRANSACT2_FINDNOTIFYNEXT  12
 #define TRANSACT2_MKDIR           13
 
-#define PTR_DIFF(p1, p2) ((size_t)(((const char *)(p1)) - (const char *)(p2)))
-
 /* some protos */
 const u_char *smb_fdata(netdissect_options *, const u_char *, const char *, const u_char *, int);
 extern const char *smb_errstr(int, int);
index 835f6f631d2366ca466eb20a8bedd28cd4d417d5..817573e40d42024209683199581cf208a09596c5 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -242,7 +242,7 @@ name_len(netdissect_options *ndo,
        s += GET_U_1(s) + 1;
        ND_TCHECK_1(s);
     }
-    return(PTR_DIFF(s, s0) + 1);
+    return(ND_BYTES_BETWEEN(s, s0) + 1);
 
 trunc:
     return(-1);        /* name goes past the end of the buffer */
@@ -330,7 +330,7 @@ write_bits(netdissect_options *ndo,
     u_int i = 0;
 
     while ((p = strchr(fmt, '|'))) {
-       size_t l = PTR_DIFF(p, fmt);
+       u_int l = ND_BYTES_BETWEEN(p, fmt);
        if (l && (val & (1 << i)))
            ND_PRINT("%.*s ", (int)l, fmt);
        fmt = p + 1;
@@ -464,7 +464,7 @@ smb_fdata1(netdissect_options *ndo,
            u_int l;
 
            p = strchr(++fmt, '}');
-           l = PTR_DIFF(p, fmt);
+           l = ND_BYTES_BETWEEN(p, fmt);
 
            if (l > sizeof(bitfmt) - 1)
                l = sizeof(bitfmt)-1;
@@ -728,7 +728,7 @@ smb_fdata1(netdissect_options *ndo,
 
            switch (t) {
            case 1:
-               name_type = name_extract(ndo, startbuf, PTR_DIFF(buf, startbuf),
+               name_type = name_extract(ndo, startbuf, ND_BYTES_BETWEEN(buf, startbuf),
                    maxbuf, nbuf);
                if (name_type < 0)
                    goto trunc;
@@ -885,8 +885,8 @@ smb_fdata(netdissect_options *ndo,
        }
     }
     if (!depth && buf < maxbuf) {
-       size_t len = PTR_DIFF(maxbuf, buf);
-       ND_PRINT("Data: (%lu bytes)\n", (unsigned long)len);
+       u_int len = ND_BYTES_BETWEEN(maxbuf, buf);
+       ND_PRINT("Data: (%u bytes)\n", len);
        smb_data_print(ndo, buf, len);
        return(buf + len);
     }