An interesting warning

Eric S. Raymond esr at thyrsus.com
Mon Nov 30 13:28:07 UTC 2015


Hal Murray <hmurray at megapathdsl.net>:
> It's from Debian wheezy (and decendents like Rasbian)
> gcc (Debian 4.7.2-5) 4.7.2
> 
> [109/174] Compiling ntpd/ntp_io.c
> ../ntpd/ntp_io.c: In function ‘process_routing_msgs’:
> ../ntpd/ntp_io.c:4629:7: warning: comparison between signed and unsigned 
> integer expressions [-Wsign-compare]
> 
> That line of code is:
>              NLMSG_OK(nh, cnt);
> It's the middle term in a for loop.
> 
> nh is a pointer, cnt is an int.
> 
> NLMSG_OK comes from /usr/include/linux/netlink.h
> #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
>                            (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
>                            (nlh)->nlmsg_len <= (len))
> nlmsg_len comes from a struct nlmsghdr:
>         __u32           nlmsg_len;      /* Length of message including header 
> */
> 
> That part of the header didn't change from wheezy to jessie.
> 
> The 3rd term is comparing an unsigned with an int.  So the real question is 
> why the compiler on other systems don't complain.
> 
> Is there a clean fix for this, or do we just document it as a glitch in this 
> environment?

Try replacing the call with NLMSG_OK(nh, (uint32_t)cnt). That might do it.

But please test in other environments before you commit.  It seems to me
the most likely reason that this error isn't everywhere is that the
type declaration of nlmsg_len is not stable across NLS versions.  If so,
trying to fix this could induce more warnings than it solves.
-- 
		<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>


More information about the devel mailing list