netcdf-c
netcdf-c copied to clipboard
Fix most warnings in libdap2
I think most of the remaining warnings in libdap2 are suspicious. For example, there are some (duplicated, but that's a different matter) functions for finding the index of an element in an NClist
that return -1
if the element isn't found. This is never checked, and is used as a size_t
. There are various options for fixing this, but I've left them as-is, or changed types so that the warning is a much more explicit:
warning: unsigned conversion from ‘int’ to ‘size_t’ {aka ‘long unsigned int’} changes value from ‘-1’ to ‘18446744073709551615’
Thanks for all this warnings work!
Every time we release code with warnings, an angel kicks a kitten right in the face.
In my branch with everything merged, I'm down to 370 warnings from 2405 in November.
There are 11 warnings remaining in libdap2
and they're all suspicious, for example:
static size_t
findin(CDFnode* parent, CDFnode* child)
{
NClist* subnodes = parent->subnodes;
for(size_t i=0;i<nclistlength(subnodes);i++) {
if(nclistget(subnodes,i) == child)
return i;
}
return -1; // Conversion warning
}
There's also no checking at the call site, so I guess this is expected to always find child
? In which case, maybe it's better to hard error here?
The other warnings are similar, indicating missing checks.