Static code analysis of OPAL
I have run the OPAL source code through the static analysis tool cppcheck (http://cppcheck.sourceforge.net/). The log is attached (cppcheck v2.4.1 - updated 18-06-2021, commit 052a732c).
I started using it after I lost access to Coverity, which I had access to at CERN and which I found quite useful. Cppcheck is also quite good, but not so extensive and has no GUI.
Just as an example, memory leaks are flagged sometimes since there is a leak in one of the logical branches:
[src/Classic/AbsBeamline/Cyclotron.cpp:931]: (error) Resource leak: f
The line reads:
931: CHECK_CYC_FSCANF_EOF(fscanf(f, "%lf", &BP.rmin));
CHECK_CYC_FSCANF_EOF can throw,
f is leaked in that case. But I would say this is (close to) a false positive, and doesn't need fixing. Other things that are flagged are somewhat personal style. But often these can also indicate bugs or typos. In general there are few false positives.
The log file contains certainly some things I think should be fixed like the usual uninitialised members, unused variables, etc. And others that I would leave. There are different categories. I fixed most of the few errors it found in src/src (see 4359206a).
Over time, I plan to go through, fix some of the simpler and more serious ones, make separate issues for the more complicated ones and rerun.
Please have a look if there are any issues in the code parts that you are maintaining.