A full build goes from 2066 warnings to 882. The two categories dealt with here
were 1409 of those, and neither was telling us anything.
-Wunused-but-set-variable (303, across 66 files) is switched off in
configure.ac, alongside the -Wno-unused-parameter and -Wno-unused-function that
were already there - same reasoning, they are almost all leftovers from removed
debug and trace code. This needs configure regenerating, hence the change to
the checked-in configure as well.
-Wsign-compare (1106) is NOT switched off, because the category is not uniformly
noise. It splits three ways:
880 for (a=0; a<x.x_len; a++) counter is int, length is u_int
178 if/while comparisons
13 A4GL_assertion() bounds checks
35 other
Only the first group is meaningless: the counter starts at zero, so the signed
comparison is what was meant all along. Those are now cast - 829 rewritten
mechanically from the compiler's own diagnostics and verified by rebuilding,
plus 3 by hand in ace.yacc, screen.yacc and helper_funcs.ec, which the script
skipped because a #line directive makes the reported column unreliable.
The other 226 are left visible on purpose. The assertions are the reason:
A4GL_assertion(u->variable_id >= ...->variables.variables_len, "Invalid VARIABLE ID");
a negative variable_id converts to a huge unsigned here, so the assertion fires
and catches it. Casting the length to int would let a negative index through
into the array access. Anything that hides this category hides that too.
Two of the casts change behaviour, both for the better:
lib/libform/form_generic/formwrite2.c:439
lib/liblex/lex_esqlc/compile_c.c:2927
for (a = 0; a < (int)(len - 1); a++)
With len==0 the old code computed 0-1 as unsigned, so an empty list ran the
loop UINT_MAX times instead of not at all. Both loops mean "all but the last
element", and now they do that.
What is left: format-overflow 159 (sprintf in the yacc grammars, worth a proper
look), unused-variable 64, missing-prototypes 61, unused-const-variable 48,
redundant-decls 48, plus the bison grammar warnings and the ~19 real bug
candidates noted previously.