So, clang has a static analyser. This effectively builds and does a deep analysis on the resultant binary for possible coding errors such as memory loss, dead code, etc. I’ve always run dhcpcd using valgrind, a memory debugger which has (and still does!) served me well over the years alongside hard compiler warning flags. So I thought dhcpcd will be pretty good after running it through the analyser.

Boy was I wrong!

Well, not wrong, but a tiny bit annoyed. It did catch some false positives, but only because I know some conditions are impossible but could be better expressed so the pass the analyser. here is a good example of what I mean. The 1st two changes don’t change anything in the real world, but do make the code easier to read and thus easier to analyse.

However, it has caught some real errors which can could problems in the real world. Nothing really earth shattering, but I like being a perfectionist! During this process I also discovered that hard coding CC in Makefiles can be a bad thing. So we now just honour CC as set by the environment and default to using the make default or cc if not set.

So to test clang analyser on the latest dhcpcd head you can do this

./configure
make clean
scan-build make

and check the results!