diff mbox series

[OpenWrt-Devel,libnl-tiny,4/5] iron out all extra compiler warnings

Message ID 20191021093642.3118-4-ynezz@true.cz
State Accepted
Delegated to: Petr Štetiar
Headers show
Series [OpenWrt-Devel,libnl-tiny,1/5] refactor into separate Git project | expand

Commit Message

Petr Štetiar Oct. 21, 2019, 9:36 a.m. UTC
gcc 9.1 on x86/64 has reported following:

 attr.c:403:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Werror=sign-compare]
 genl.c:154:24: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
 genl_mngt.c:157:22: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Werror=sign-compare]
 msg.c:190:20: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Werror=sign-compare]
 msg.c:192:18: error: comparison of integer expressions of different signedness: ‘__u32’ {aka ‘const unsigned int’} and ‘int’ [-Werror=sign-compare]
 msg.c:361:10: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
 nl.c:428:18: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
 nl.c:602:23: error: comparison of integer expressions of different signedness: ‘__u32’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare]

Signed-off-by: Petr Štetiar <ynezz@true.cz>
---
 attr.c      | 6 ++++--
 genl.c      | 2 +-
 genl_mngt.c | 2 +-
 msg.c       | 8 +++++---
 nl.c        | 4 ++--
 5 files changed, 13 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/attr.c b/attr.c
index e0f50611cff9..eae91e52bcac 100644
--- a/attr.c
+++ b/attr.c
@@ -400,9 +400,11 @@ 
  */
 int nla_ok(const struct nlattr *nla, int remaining)
 {
-	return remaining >= sizeof(*nla) &&
+	size_t r = remaining;
+
+	return r >= sizeof(*nla) &&
 	       nla->nla_len >= sizeof(*nla) &&
-	       nla->nla_len <= remaining;
+	       nla->nla_len <= r;
 }
 
 /**
diff --git a/genl.c b/genl.c
index 055be919e1d3..f1df3f060c87 100644
--- a/genl.c
+++ b/genl.c
@@ -151,7 +151,7 @@  int genlmsg_valid_hdr(struct nlmsghdr *nlh, int hdrlen)
 		return 0;
 
 	ghdr = nlmsg_data(nlh);
-	if (genlmsg_len(ghdr) < NLMSG_ALIGN(hdrlen))
+	if ((unsigned) genlmsg_len(ghdr) < NLMSG_ALIGN(hdrlen))
 		return 0;
 
 	return 1;
diff --git a/genl_mngt.c b/genl_mngt.c
index 246521f696a2..3b603c7ac9bb 100644
--- a/genl_mngt.c
+++ b/genl_mngt.c
@@ -154,7 +154,7 @@  int genl_register(struct nl_cache_ops *ops)
 		goto errout;
 	}
 
-	if (ops->co_hdrsize < GENL_HDRSIZE(0)) {
+	if ((size_t) ops->co_hdrsize < GENL_HDRSIZE(0)) {
 		err = -NLE_INVAL;
 		goto errout;
 	}
diff --git a/msg.c b/msg.c
index b502047c4c74..5992e381813b 100644
--- a/msg.c
+++ b/msg.c
@@ -187,9 +187,11 @@  static size_t default_msg_size = 4096;
  */
 int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
 {
-	return (remaining >= sizeof(struct nlmsghdr) &&
+	size_t r = remaining;
+
+	return (r >= sizeof(struct nlmsghdr) &&
 		nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
-		nlh->nlmsg_len <= remaining);
+		nlh->nlmsg_len <= r);
 }
 
 /**
@@ -358,7 +360,7 @@  struct nl_msg *nlmsg_alloc_simple(int nlmsgtype, int flags)
  */
 void nlmsg_set_default_size(size_t max)
 {
-	if (max < nlmsg_total_size(0))
+	if (max < (size_t) nlmsg_total_size(0))
 		max = nlmsg_total_size(0);
 
 	default_msg_size = max;
diff --git a/nl.c b/nl.c
index 2fb866eca903..2649470f542f 100644
--- a/nl.c
+++ b/nl.c
@@ -425,7 +425,7 @@  retry:
 		}
 	}
 
-	if (iov.iov_len < n ||
+	if (iov.iov_len < (size_t) n ||
 	    msg.msg_flags & MSG_TRUNC) {
 		/* Provided buffer is not long enough, enlarge it
 		 * and try again. */
@@ -599,7 +599,7 @@  continue_reading:
 		else if (hdr->nlmsg_type == NLMSG_ERROR) {
 			struct nlmsgerr *e = nlmsg_data(hdr);
 
-			if (hdr->nlmsg_len < nlmsg_msg_size(sizeof(*e))) {
+			if (hdr->nlmsg_len < (unsigned) nlmsg_msg_size(sizeof(*e))) {
 				/* Truncated error message, the default action
 				 * is to stop parsing. The user may overrule
 				 * this action by returning NL_SKIP or