From: Ben Pfaff Date: Fri, 15 Apr 2011 16:39:08 +0000 (-0700) Subject: Avoid warnings about comparisons that are always true. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5160ab34f8e97de8985d75d77c029324e4bccdab;p=openvswitch Avoid warnings about comparisons that are always true. The range of "enum" types varies from one ABI to another. If the enums being tested in these functions happen to be 16 bits wide, then GCC may issue a warning because, in such a case, the comparison is always true. Using an int instead of a uint16_t avoids that particular problem and should suppress the warning. Fixes the following reported warnings: lib/ofp-print.c:240: warning: comparison is always true due to limited range of data type lib/ofp-util.c:1973: warning: comparison is always false due to limited range of data type Reported-by: YAMAMOTO Takashi --- diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 6560f32a..30f6d374 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -227,7 +227,7 @@ nx_action_len(enum nx_action_subtype subtype) static void ofp_print_nx_action(struct ds *string, const struct nx_action_header *nah) { - uint16_t subtype = ntohs(nah->subtype); + int subtype = ntohs(nah->subtype); int required_len = nx_action_len(subtype); int len = ntohs(nah->len); @@ -312,7 +312,7 @@ ofp_print_nx_action(struct ds *string, const struct nx_action_header *nah) } } - ds_put_format(string, "***unknown Nicira action:%"PRIu16"***", subtype); + ds_put_format(string, "***unknown Nicira action:%d***", subtype); } static int diff --git a/lib/ofp-util.c b/lib/ofp-util.c index c49b0798..bcaf3ddc 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -1959,7 +1959,7 @@ check_nicira_action(const union ofp_action *a, unsigned int len, const struct flow *flow) { const struct nx_action_header *nah; - uint16_t subtype; + int subtype; int error; if (len < 16) { @@ -1971,7 +1971,7 @@ check_nicira_action(const union ofp_action *a, unsigned int len, subtype = ntohs(nah->subtype); if (subtype > TYPE_MAXIMUM(enum nx_action_subtype)) { - /* This is necessary because enum nx_action_subtype is probably an + /* This is necessary because enum nx_action_subtype may be an * 8-bit type, so the cast below throws away the top 8 bits. */ return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_BAD_VENDOR_TYPE); } @@ -2026,8 +2026,7 @@ check_nicira_action(const union ofp_action *a, unsigned int len, case NXAST_SNAT__OBSOLETE: default: VLOG_WARN_RL(&bad_ofmsg_rl, - "unknown Nicira vendor action subtype %"PRIu16, - ntohs(nah->subtype)); + "unknown Nicira vendor action subtype %d", subtype); return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_BAD_VENDOR_TYPE); } }