[PATCH v2] Remove pointless N < 0 checks

Thomas Graf tgraf at suug.ch
Tue Aug 26 05:08:41 PDT 2014


route/tc.c:553:9: warning: comparison of unsigned enum expression < 0 is
always false [-Wtautological-compare]
              if (id < 0 || id > RTNL_TC_STATS_MAX)

Signed-off-by: Thomas Graf <tgraf at suug.ch>
---
v2: Add cast to unsigned int as suggested by Thomas Haller

 lib/handlers.c | 8 ++++----
 lib/route/tc.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/handlers.c b/lib/handlers.c
index a6a97bb..97a0d9c 100644
--- a/lib/handlers.c
+++ b/lib/handlers.c
@@ -203,7 +203,7 @@ struct nl_cb *nl_cb_alloc(enum nl_cb_kind kind)
 	int i;
 	struct nl_cb *cb;
 
-	if (kind < 0 || kind > NL_CB_KIND_MAX)
+	if ((unsigned int) kind > NL_CB_KIND_MAX)
 		return NULL;
 
 	cb = calloc(1, sizeof(*cb));
@@ -293,10 +293,10 @@ enum nl_cb_type nl_cb_active_type(struct nl_cb *cb)
 int nl_cb_set(struct nl_cb *cb, enum nl_cb_type type, enum nl_cb_kind kind,
 	      nl_recvmsg_msg_cb_t func, void *arg)
 {
-	if (type < 0 || type > NL_CB_TYPE_MAX)
+	if ((unsigned int) type > NL_CB_TYPE_MAX)
 		return -NLE_RANGE;
 
-	if (kind < 0 || kind > NL_CB_KIND_MAX)
+	if ((unsigned int) kind > NL_CB_KIND_MAX)
 		return -NLE_RANGE;
 
 	if (kind == NL_CB_CUSTOM) {
@@ -343,7 +343,7 @@ int nl_cb_set_all(struct nl_cb *cb, enum nl_cb_kind kind,
 int nl_cb_err(struct nl_cb *cb, enum nl_cb_kind kind,
 	      nl_recvmsg_err_cb_t func, void *arg)
 {
-	if (kind < 0 || kind > NL_CB_KIND_MAX)
+	if ((unsigned int) kind > NL_CB_KIND_MAX)
 		return -NLE_RANGE;
 
 	if (kind == NL_CB_CUSTOM) {
diff --git a/lib/route/tc.c b/lib/route/tc.c
index 34c3b57..53b69d5 100644
--- a/lib/route/tc.c
+++ b/lib/route/tc.c
@@ -550,7 +550,7 @@ char *rtnl_tc_get_kind(struct rtnl_tc *tc)
  */
 uint64_t rtnl_tc_get_stat(struct rtnl_tc *tc, enum rtnl_tc_stat id)
 {
-	if (id < 0 || id > RTNL_TC_STATS_MAX)
+	if ((unsigned int) id > RTNL_TC_STATS_MAX)
 		return 0;
 
 	return tc->tc_stats[id];
-- 
1.9.3




More information about the libnl mailing list