[PATCH 1/6] Remove pointless N < 0 checks

Thomas Graf tgraf at suug.ch
Tue Aug 26 03:06:52 PDT 2014


On 08/26/14 at 12:00pm, Thomas Haller wrote:
> On Tue, 2014-08-26 at 01:09 +0200, Thomas Graf wrote:
> > 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>
> > ---
> >  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..9cf5a96 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 (kind > NL_CB_KIND_MAX)
> >  		return NULL;
> 
> 
> Isn't the signedness of enums implementation defined?
> 
> For NetworkManager we did instead:
> http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=a2a36d845066a5e3ad1b6d2953993a1a433340ff

Casting would be even better. I agree. Feel free to drop this
patch of the series and I will resend with casting in place.



More information about the libnl mailing list