On Thu, Jul 27, 2017 at 07:48:24PM +0000, Florian Obser wrote: > /usr/src/usr.bin/netstat/inet.c:342:19: warning: comparison of unsigned > expression < 0 is always false [-Wtautological-compare] > if (kf->t_state < 0 || kf->t_state >= TCP_NSTATES) > ~~~~~~~~~~~ ^ ~ > > t_state is uint32_t, I was toying with the idea of printing is as a > short which is what we originally get passed in, but I think it's > better for debugging purposes to show what we actually got hence the %u. > > OK? > > diff --git usr.bin/netstat/inet.c usr.bin/netstat/inet.c > index 979750dad8e..dd10b6ee834 100644 > --- usr.bin/netstat/inet.c > +++ usr.bin/netstat/inet.c > @@ -339,8 +339,8 @@ netdomainpr(struct kinfo_file *kf, int proto) > inetprint(&faddr, kf->inp_fport, name, 0); > } > if (istcp) { > - if (kf->t_state < 0 || kf->t_state >= TCP_NSTATES) > - printf(" %d", kf->t_state); > + if (kf->t_state >= TCP_NSTATES) > + printf(" %u", kf->t_state); > else > printf(" %s", tcpstates[kf->t_state]); > } else if (kf->so_type == SOCK_RAW) { >
OK, even though I think the compiler is stupid here. Why is this not just silently optimized away? If the type of a variable ever changes the compiler will not warn that now you do need to check for < 0. I wonder how often bugs get introduced because of this warning... -- :wq Claudio