Another lesson on compare warnings please ...
Hal Murray
hmurray at megapathdsl.net
Wed Nov 25 08:54:09 UTC 2015
In ntpd/refclock_palisade.h
short rpt_cnt; /* TSIP packet length so far */
char rpt_buf[BMAX]; /* packet assembly buffer */
>From ntpd/refclock_palisade.c
else if (up->rpt_cnt > BMAX)
That code is correct, but I would have used sizeof(rpt_buf) rather than BMAX.
With a little bit of poking around, you can figure out that rpt_buf is the
buffer. With BMAX, you have to go look in another file to see that it's the
size of the buffer.
But that gets:
../ntpd/refclock_palisade.c:1415:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if (up->rpt_cnt > sizeof(up->rpt_buf)) {
Both BMAX and sizeof work if I change the short to u_int.
So what is the type of sizeof, and what is the type of a literal constant? I expected them to be the same.
What is the best way to do this sort of thing?
Do I get a segfault if I botch something and get an underflow on a unsigned int and then use it as an index with a 64 bit pointer?
--
These are my opinions. I hate spam.
More information about the devel
mailing list