An interesting warning
joel at rtems.org
Mon Nov 30 14:02:02 UTC 2015
On Nov 30, 2015 8:28 AM, "Eric S. Raymond" <esr at thyrsus.com> wrote:
> 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
> > */
> > 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
> > 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
> > environment?
> Try replacing the call with NLMSG_OK(nh, (uint32_t)cnt). That might do it.
Sizes should be size_t. That's the crux of the problem although it likely
Also.. Is there a style rule for macro argument names? I thought it was
considered bad form to use arguments without leading _. The name len seems
common and could lead to unexpected side-effects.
> 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.
What other types is it?
> <a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
> devel mailing list
> devel at ntpsec.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the devel