[cmds] Fix compiler warnings based on added -Wextra flag #2111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.