From: Francois-Xavier Le Bail Date: Mon, 26 Feb 2024 18:41:37 +0000 (+0100) Subject: Replace '> 0' with '!= 0' in some unsigned expression tests X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/07e0b558f42fcdb78e7410177b66c004e430c83b Replace '> 0' with '!= 0' in some unsigned expression tests Unsigned is always >= 0, so '> 0' and '!= 0' are identical. This makes the tests a little clearer. --- diff --git a/print-arp.c b/print-arp.c index 67bee441..3f6c0261 100644 --- a/print-arp.c +++ b/print-arp.c @@ -179,7 +179,7 @@ struct atmarp_pkthdr { static int isnonzero(netdissect_options *ndo, const u_char *a, size_t len) { - while (len > 0) { + while (len != 0) { if (GET_U_1(a) != 0) return (1); a++; diff --git a/print-ascii.c b/print-ascii.c index 71db40dd..4006c42b 100644 --- a/print-ascii.c +++ b/print-ascii.c @@ -73,7 +73,7 @@ ascii_print(netdissect_options *ndo, truncated = TRUE; } ND_PRINT("\n"); - while (length > 0) { + while (length != 0) { s = GET_U_1(cp); cp++; length--; diff --git a/print-bootp.c b/print-bootp.c index 0b80bcd1..e06943cb 100644 --- a/print-bootp.c +++ b/print-bootp.c @@ -651,7 +651,7 @@ rfc1048_print(netdissect_options *ndo, if (tag == TAG_PARM_REQUEST) { idx = 0; - while (len > 0) { + while (len != 0) { uint8_t innertag = GET_U_1(bp); bp++; len--; @@ -736,7 +736,7 @@ rfc1048_print(netdissect_options *ndo, case 'B': /* boolean */ - while (len > 0) { + while (len != 0) { uint8_t bool_value; if (!first) ND_PRINT(","); @@ -762,7 +762,7 @@ rfc1048_print(netdissect_options *ndo, case 'x': default: /* Bytes */ - while (len > 0) { + while (len != 0) { uint8_t byte_value; if (!first) ND_PRINT(c == 'x' ? ":" : "."); @@ -853,7 +853,7 @@ rfc1048_print(netdissect_options *ndo, break; } else { ND_PRINT("%s ", tok2str(arp2str, "hardware-type %u,", type)); - while (len > 0) { + while (len != 0) { if (!first) ND_PRINT(":"); ND_PRINT("%02x", GET_U_1(bp)); @@ -913,7 +913,7 @@ rfc1048_print(netdissect_options *ndo, len = 0; break; } - while (len > 0) { + while (len != 0) { if (!first) ND_PRINT(","); mask_width = GET_U_1(bp); @@ -968,7 +968,7 @@ rfc1048_print(netdissect_options *ndo, len = 0; break; } - while (len > 0) { + while (len != 0) { suboptlen = GET_U_1(bp); bp++; len--; diff --git a/print-cdp.c b/print-cdp.c index c66c0d11..f8e9d785 100644 --- a/print-cdp.c +++ b/print-cdp.c @@ -482,7 +482,7 @@ cdp_print_prefixes(netdissect_options *ndo, ND_PRINT(" IPv4 Prefixes (%u):", l / 5); - while (l > 0) { + while (l != 0) { ND_PRINT(" %u.%u.%u.%u/%u", GET_U_1(p), GET_U_1(p + 1), GET_U_1(p + 2), GET_U_1(p + 3), GET_U_1(p + 4)); diff --git a/print-cfm.c b/print-cfm.c index be32acfe..fcc2862f 100644 --- a/print-cfm.c +++ b/print-cfm.c @@ -528,7 +528,7 @@ cfm_print(netdissect_options *ndo, tptr += first_tlv_offset; tlen -= first_tlv_offset; - while (tlen > 0) { + while (tlen != 0) { cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr; /* Enough to read the tlv type ? */ diff --git a/print-dvmrp.c b/print-dvmrp.c index 6d6d7c19..85bbde65 100644 --- a/print-dvmrp.c +++ b/print-dvmrp.c @@ -152,7 +152,7 @@ print_report(netdissect_options *ndo, u_int metric, done; u_int i, width; - while (len > 0) { + while (len != 0) { if (len < 3) { ND_PRINT(" [length %u < 3]", len); goto invalid; @@ -214,7 +214,7 @@ print_probe(netdissect_options *ndo, bp += 4; len -= 4; - while (len > 0) { + while (len != 0) { if (len < 4) { ND_PRINT("[remaining length %u < 4]", len); goto invalid; @@ -238,7 +238,7 @@ print_neighbors(netdissect_options *ndo, u_char thresh; int ncount; - while (len > 0) { + while (len != 0) { if (len < 7) { ND_PRINT(" [length %u < 7]", len); goto invalid; @@ -282,7 +282,7 @@ print_neighbors2(netdissect_options *ndo, ND_PRINT(" (v %u.%u):", major_version, minor_version); - while (len > 0) { + while (len != 0) { if (len < 8) { ND_PRINT(" [length %u < 8]", len); goto invalid; @@ -298,7 +298,7 @@ print_neighbors2(netdissect_options *ndo, ncount = GET_U_1(bp); bp++; len -= 8; - while (--ncount >= 0 && len > 0) { + while (--ncount >= 0 && len != 0) { if (len < 4) { ND_PRINT(" [length %u < 4]", len); goto invalid; diff --git a/print-eigrp.c b/print-eigrp.c index d4eced42..647f353b 100644 --- a/print-eigrp.c +++ b/print-eigrp.c @@ -279,7 +279,7 @@ eigrp_print(netdissect_options *ndo, const u_char *pptr, u_int len) tptr+=sizeof(struct eigrp_common_header); - while(tlen>0) { + while(tlen != 0) { if (tlen < sizeof(struct eigrp_tlv_header)) { ND_PRINT("\n\t (only %u bytes of data)", tlen); goto invalid; diff --git a/print-geneve.c b/print-geneve.c index 59dca93e..e148eb4a 100644 --- a/print-geneve.c +++ b/print-geneve.c @@ -164,7 +164,7 @@ geneve_opts_print(netdissect_options *ndo, const u_char *bp, u_int len) { const char *sep = ""; - while (len > 0) { + while (len != 0) { uint16_t opt_class; uint8_t opt_type; uint8_t opt_len; diff --git a/print-icmp.c b/print-icmp.c index a4564b53..b446075a 100644 --- a/print-icmp.c +++ b/print-icmp.c @@ -754,7 +754,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, break; } idp = (const struct id_rdiscovery *)&dp->icmp_data; - while (num > 0) { + while (num != 0) { (void)snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}", GET_IPADDR_STRING(idp->ird_addr), GET_BE_U_4(idp->ird_pref)); diff --git a/print-isoclns.c b/print-isoclns.c index 4732ec0b..3ac10c0d 100644 --- a/print-isoclns.c +++ b/print-isoclns.c @@ -1015,7 +1015,7 @@ clnp_print(netdissect_options *ndo, } tptr+=nsap_offset; tlen-=nsap_offset; - while (tlen > 0) { + while (tlen != 0) { source_address_length=GET_U_1(tptr); if (tlen < source_address_length+1) { ND_PRINT("\n\t NSAP address goes past end of option"); @@ -1327,7 +1327,7 @@ esis_print(netdissect_options *ndo, ND_PRINT("\n\t Number of Source Addresses: %u", source_address_number); - while (source_address_number > 0) { + while (source_address_number != 0) { ND_TCHECK_1(pptr); if (li < 1) { ND_PRINT(", bad esh/li"); @@ -1420,7 +1420,7 @@ esis_print(netdissect_options *ndo, break; case ESIS_OPTION_PROTOCOLS: - while (opli>0) { + while (opli != 0) { ND_PRINT("%s (0x%02x)", tok2str(nlpid_values, "unknown", @@ -1804,7 +1804,7 @@ isis_print_tlv_ip_reach(netdissect_options *ndo, tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp; - while (length > 0) { + while (length != 0) { if ((size_t)length < sizeof(*tlv_ip_reach)) { ND_PRINT("short IPv4 Reachability (%u vs %zu)", length, @@ -2338,7 +2338,7 @@ isis_print_extd_ip_reach(netdissect_options *ndo, processed+=sublen+1; ND_PRINT(" (%u)", sublen); /* print out subTLV length */ - while (sublen>0) { + while (sublen != 0) { subtlvtype=GET_U_1(tptr); subtlvlen=GET_U_1(tptr + 1); tptr+=2; @@ -2846,7 +2846,7 @@ isis_print(netdissect_options *ndo, * Now print the TLV's. */ - while (packet_len > 0) { + while (packet_len != 0) { ND_TCHECK_2(pptr); if (packet_len < 2) goto trunc; diff --git a/print-ldp.c b/print-ldp.c index 50d14601..60fe0105 100644 --- a/print-ldp.c +++ b/print-ldp.c @@ -689,7 +689,7 @@ ldp_pdu_print(netdissect_options *ndo, tptr = pptr + sizeof(struct ldp_common_header); tlen = pdu_len - (sizeof(struct ldp_common_header)-4); /* Type & Length fields not included */ - while(tlen>0) { + while(tlen != 0) { /* did we capture enough for fully decoding the msg header ? */ ND_TCHECK_LEN(tptr, sizeof(struct ldp_msg_header)); diff --git a/print-lldp.c b/print-lldp.c index 2df9aca3..33e9859c 100644 --- a/print-lldp.c +++ b/print-lldp.c @@ -1088,7 +1088,7 @@ lldp_private_tia_print(netdissect_options *ndo, tptr = tptr + 9; /* Decode each civic address element */ - while (lci_len > 0) { + while (lci_len != 0) { if (lci_len < 2) { return hexdump; } diff --git a/print-lmp.c b/print-lmp.c index bcd69e7b..3b9bb0f2 100644 --- a/print-lmp.c +++ b/print-lmp.c @@ -477,7 +477,7 @@ lmp_print(netdissect_options *ndo, tptr+=sizeof(struct lmp_common_header); tlen-=sizeof(struct lmp_common_header); - while(tlen>0) { + while(tlen != 0) { const struct lmp_object_header *lmp_obj_header = (const struct lmp_object_header *)tptr; lmp_obj_len=GET_BE_U_2(lmp_obj_header->length); diff --git a/print-nflog.c b/print-nflog.c index f90554a2..8db5a7a2 100644 --- a/print-nflog.c +++ b/print-nflog.c @@ -169,7 +169,7 @@ nflog_if_print(netdissect_options *ndo, length -= NFLOG_HDR_LEN; caplen -= NFLOG_HDR_LEN; - while (length > 0) { + while (length != 0) { const nflog_tlv_t *tlv; ND_ICHECK_ZU(length, <, NFLOG_TLV_LEN); diff --git a/print-ospf6.c b/print-ospf6.c index b1325364..5eda0842 100644 --- a/print-ospf6.c +++ b/print-ospf6.c @@ -661,7 +661,7 @@ ospf6_print_lsa(netdissect_options *ndo, prefixes); tptr = (const uint8_t *)llsap->llsa_prefix; - while (prefixes > 0) { + while (prefixes != 0) { bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); if (bytelen < 0) goto trunc; @@ -693,7 +693,7 @@ ospf6_print_lsa(netdissect_options *ndo, ND_PRINT("\n\t Prefixes %u:", prefixes); tptr = (const uint8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix; - while (prefixes > 0) { + while (prefixes != 0) { bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); if (bytelen < 0) goto trunc; diff --git a/print-pim.c b/print-pim.c index 2a33c1ff..70948cda 100644 --- a/print-pim.c +++ b/print-pim.c @@ -756,7 +756,7 @@ pimv2_print(netdissect_options *ndo, case PIMV2_TYPE_HELLO: { uint16_t otype, olen; - while (len > 0) { + while (len != 0) { if (len < 4) goto trunc; otype = GET_BE_U_2(bp); diff --git a/print-radius.c b/print-radius.c index 76a9923a..fba8b8f4 100644 --- a/print-radius.c +++ b/print-radius.c @@ -1317,7 +1317,7 @@ radius_attrs_print(netdissect_options *ndo, const char *attr_string; uint8_t type, len; - while (length > 0) { + while (length != 0) { ND_ICHECK_U(length, <, 2); type = GET_U_1(rad_attr->type); diff --git a/print-resp.c b/print-resp.c index 7388a73f..db2f1d17 100644 --- a/print-resp.c +++ b/print-resp.c @@ -214,7 +214,7 @@ resp_print(netdissect_options *ndo, const u_char *bp, u_int length) ndo->ndo_protocol = "resp"; ND_PRINT(": RESP"); - while (length > 0) { + while (length != 0) { /* * This block supports redis pipelining. * For example, multiple operations can be pipelined within the same string: diff --git a/print-rpki-rtr.c b/print-rpki-rtr.c index 334720f1..574f3f05 100644 --- a/print-rpki-rtr.c +++ b/print-rpki-rtr.c @@ -153,7 +153,7 @@ indent_string (u_int indent) indent -= 8; } - while (indent > 0) { + while (indent != 0) { buf[idx] = ' '; idx++; indent--; diff --git a/print-rsvp.c b/print-rsvp.c index c577ec1c..0a289ee6 100644 --- a/print-rsvp.c +++ b/print-rsvp.c @@ -1236,7 +1236,7 @@ rsvp_obj_print(netdissect_options *ndo, /* read variable length subobjects */ total_subobj_len = obj_tlen; - while(total_subobj_len > 0) { + while(total_subobj_len != 0) { /* If RFC 3476 Section 3.1 defined that a sub-object of the * GENERALIZED_UNI RSVP object must have the Length field as * a multiple of 4, instead of the check below it would be @@ -1965,7 +1965,7 @@ rsvp_print(netdissect_options *ndo, * Bundle messages may not contain bundle submessages, so we don't * need to handle bundle submessages specially. */ - while(tlen > 0) { + while(tlen != 0) { const u_char *subpptr=tptr, *subtptr; u_short subplen, subtlen; diff --git a/print-sflow.c b/print-sflow.c index 0b6a832e..3934cd9a 100644 --- a/print-sflow.c +++ b/print-sflow.c @@ -494,7 +494,7 @@ sflow_print_counter_records(netdissect_options *ndo, tptr = pointer; tlen = len; - while (nrecords > 0) { + while (nrecords != 0) { /* do we have the "header?" */ if (tlen < sizeof(struct sflow_counter_record_t)) return 1; @@ -683,7 +683,7 @@ sflow_print_flow_records(netdissect_options *ndo, tptr = pointer; tlen = len; - while (nrecords > 0) { + while (nrecords != 0) { /* do we have the "header?" */ if (tlen < sizeof(struct sflow_flow_record_t)) return 1; @@ -896,7 +896,7 @@ sflow_print(netdissect_options *ndo, tptr += sizeof(struct sflow_v6_datagram_t); tlen -= sizeof(struct sflow_v6_datagram_t); } - while (nsamples > 0 && tlen > 0) { + while (nsamples != 0 && tlen != 0) { sflow_sample = (const struct sflow_sample_header *)tptr; sflow_sample_type = (GET_BE_U_4(sflow_sample->format)&0x0FFF); diff --git a/print-slow.c b/print-slow.c index 8a75edcc..f2773401 100644 --- a/print-slow.c +++ b/print-slow.c @@ -355,7 +355,7 @@ slow_marker_lacp_print(netdissect_options *ndo, const struct marker_tlv_marker_info_t *marker_tlv_marker_info; } tlv_ptr; - while(tlen>0) { + while(tlen != 0) { /* is the packet big enough to include the tlv header ? */ if (tlen < sizeof(struct tlv_header_t)) goto tooshort; @@ -525,7 +525,7 @@ slow_oam_print(netdissect_options *ndo, switch (code) { case SLOW_OAM_CODE_INFO: - while (tlen > 0) { + while (tlen != 0) { ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr; if (tlen < sizeof(*ptr.slow_oam_tlv_header)) goto tooshort; @@ -622,7 +622,7 @@ slow_oam_print(netdissect_options *ndo, tptr += 2; /* TLVs */ - while (tlen > 0) { + while (tlen != 0) { ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr; if (tlen < sizeof(*ptr.slow_oam_tlv_header)) goto tooshort; diff --git a/print-snmp.c b/print-snmp.c index d975b427..49587913 100644 --- a/print-snmp.c +++ b/print-snmp.c @@ -847,7 +847,7 @@ asn1_decode(u_char *p, u_int length) struct be elem; int i = 0; - while (i >= 0 && length > 0) { + while (i >= 0 && length != 0) { i = asn1_parse(ndo, p, length, &elem); if (i >= 0) { ND_PRINT(" "); diff --git a/print-tcp.c b/print-tcp.c index 4f91b762..308915bc 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -445,7 +445,7 @@ tcp_print(netdissect_options *ndo, hlen -= sizeof(*tp); cp = (const u_char *)tp + sizeof(*tp); ND_PRINT(", options ["); - while (hlen > 0) { + while (hlen != 0) { if (ch != '\0') ND_PRINT("%c", ch); opt = GET_U_1(cp); diff --git a/print-vtp.c b/print-vtp.c index 1637db66..cfb62dac 100644 --- a/print-vtp.c +++ b/print-vtp.c @@ -271,7 +271,7 @@ vtp_print(netdissect_options *ndo, /* TLV information follows */ - while (len > 0) { + while (len != 0) { /* * Cisco specs say 2 bytes for type + 2 bytes for length; diff --git a/util-print.c b/util-print.c index b8257674..49126bd6 100644 --- a/util-print.c +++ b/util-print.c @@ -181,7 +181,7 @@ nd_printn(netdissect_options *ndo, void nd_printjn(netdissect_options *ndo, const u_char *s, u_int n) { - while (n > 0) { + while (n != 0) { fn_print_char(ndo, GET_U_1(s)); n--; s++; @@ -200,7 +200,7 @@ nd_printjnp(netdissect_options *ndo, const u_char *s, u_int n) { u_char c; - while (n > 0) { + while (n != 0) { c = GET_U_1(s); if (c == '\0') break; @@ -376,7 +376,7 @@ unsigned_relts_print(netdissect_options *ndo, ND_PRINT("0s"); return; } - while (secs > 0) { + while (secs != 0) { if (secs >= *s) { ND_PRINT("%u%s", secs / *s, *l); secs -= (secs / *s) * *s;