[cmds] Fix compiler warnings based on added -Wextra flag by ghaerr · Pull Request #2111 · ghaerr/elks (original) (raw)
Generally straightforward changes based on the easier-to-fix issues illuminated by adding -Wextra and -Wtype-limits to the kernel, elkscmd/ and libc/ compilations. There'll be a few more warnings showing up compiling the applications in elkscmds/ until more time is available to figure out or test exactly might be incorrect.
Initially, -Wsign-compare was turned on, but signed vs unsigned comparisons can be quite tricky so only a few instances were obviously correctable. The rest will have to wait, and the warning turned off since there are a bit too many of them.
Overall, some of the warnings flagged some pretty bad, mostly error, handling in some applications. A big red flag is comparing any unsigned integer (or typedef'd type) to < 0, which is always false. Many of the kernel read/write functions return size_t, which is unsigned, so comparing their success with < 0 doesn't work. I suspect this is because of the K&R old days, when those same functions returned int and people were able to use < 0 for error checking.
The math library has a couple problems with overflow/underflow comparing to +50000/-50000 which overflows 'int'. Since I can't yet figure a way to test, those warnings have been turned off for the time being.