HDFGroup / hdf4

Official HDF4 Library Repository
Other
15 stars 25 forks source link

Fix more C warnings #32

Closed schwehr closed 1 year ago

schwehr commented 1 year ago

There are still a lot of folks using hdf4 around (I'm one of them). I've seen a few fuzzer bugs in prior versions and am having trouble getting all the platforms I have to support working with the version at head (e.g. x86-64, ppc, and arm). Before trying to dig into more, I figured I'd start with my current default compiler and see if I can do some low risk code cleanup if folks are up for it. My initial run as seeing what compiler warnings are showing up:

rm -rf build-ninja; time (mkdir -p build-ninja && cd build-ninja && cmake -DCMAKE_ANSI_CFLAGS:STRING="-Wall -Wextra -Werror -Wno-implicit-fallthrough -Wno-address -Wno-sign-compare -Wno-pedantic -Wno-stringop-truncation -Wno-type-limits -Wno-use-after-free -Wno-pointer-to-int-cast -Wno-pedantic -Wno-strict-aliasing -Wno-parentheses -Wno-tautological-compare -Wno-unused-parameter -Wno-strict-aliasing -Wno-discarded-qualifiers -Wno-implicit-function-declaration -Wno-alloc-size-larger-than -Wno-int-to-pointer-cast -Wno-array-bounds -Wno-unused-function -Wno-no-unused-const-variable= -Wno-unused-variable -Wno-memset-elt-size -Wno-maybe-uninitialized -Wno-switch -Wno-format-overflow -Wno-unused-but-set-variable" -GNinja .. && cmake --build . && ctest -V .)

I had trouble with being able to turn off -pedantic, so I commented that out in https://github.com/HDFGroup/hdf4/blob/31f75f7123037768f4bc1b4ee48321316e1eaf5b/config/cmake/HDFCompilerFlags.cmake#L159

And here here in https://github.com/HDFGroup/hdf4/blob/31f75f7123037768f4bc1b4ee48321316e1eaf5b/config/cmake/HDFCompilerFlags.cmake#L159

I will try to make some manageable pull requests that just address one of those compiler warnings at a time (as I have time).

Also, I see reference to things like VAX and $Id that are easy cleanups.

schwehr commented 1 year ago

I see a number of ways to quickly improve the HDF4 codebase so that it can live as long as possible with the minimum of future upkeep work. A lot of this stuff was done to GDAL and some to shapelib, mb-system, etc. e.g. https://github.com/OSGeo/shapelib/issues/17 And I see that there has been some start to a few of these

These can be a lot smaller:

find . -name "*.[chf]" | xargs wc -l | grep total
 273734 total
schwehr commented 1 year ago

After looking at the build system and CI setup, it looks like hdf4 would benefit from:

schwehr commented 1 year ago

More cleanup ideas

derobins commented 1 year ago

We'll be making many of these changes over the next year or so in an effort to make HDF4 into a more maintainable piece of software. Some of them will make it into 4.2.16, but others will have to wait until later in the year, as we get 4.2.17 together.

schwehr commented 1 year ago

Just a note that I've seen massive amounts of cleanup in the last couple weeks. There is alway always more that can be done, but the code is a lot easier to work with. One of the biggest improvements so far is removing a lot of the dead code.