tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Signed vs unsigned comparisons in sys/dev/pcio/if_wm.c



On Sun, Nov 13, 2016 at 09:33:53AM +0800, Paul Goyette wrote:
 > While starting to investigate the possibility of modularizing the if_wm(4)
 > driver, I discovered some issues where signed expressions are being
 > compared to unsigned expressions.  When if_wm.c is being compiled as a
 > built-in driver, these errors are ignored.  However, when build as a
 > loadable module, they are fatal to the build!

Ideally the kernel would be clean with respect to this, but there's a
*lot* of them.

There's no particular reason not to fix any particular one, provided
that you've checked to make sure it isn't going to introduce problems.
But it's best to avoid using casts just to silence the warnings... in
general size values should be unsigned as negative sizes aren't
meaningful, and then they can be compared with sizeof without causing
a warning... but when changing things to unsigned one has to be
careful to check for -1 being used as a signalling value, and also for
unsafe loops like "while (x >= 0) { stuff; x--; }".

... changing mbuf lengths to be unsigned though is a monumentally
large project ...

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index