You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I started looking into using cppcheck to analyze source code. I started with the hcana/src directory, but of course this should be applied to the entire Hall A analyzer as well, in principle.
Cppcheck produced a lot of suggestions for improvement, which break down into several categories:
a) warnings about unused variables, etc.
b) potential performance hits
c) style issues
I took some time to fix a few of the things that showed up from categories a) and b) ... that was pretty simple. However, there remain to broad types of things that cppcheck complains about:
C-style pointer casting
Failure to initialize member variables in the constructor of a class.
Below is the output of cppcheck from just one of the pieces of source code in hcana/src:
[src/THcAerogel.cxx:263]: (style) C-style pointer casting
[src/THcAerogel.cxx:267]: (style) C-style pointer casting
[src/THcAerogel.cxx:273]: (style) C-style pointer casting
[src/THcAerogel.cxx:279]: (style) C-style pointer casting
[src/THcAerogel.cxx:285]: (style) C-style pointer casting
[src/THcAerogel.cxx:305]: (style) C-style pointer casting
[src/THcAerogel.cxx:454]: (style) C-style pointer casting
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fPosGain' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fNegGain' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fA_Pos' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fA_Neg' is not initialized in the constructor.
... and so on.
Looking at the first few entries, the code looks like this:
So, you can see the type of thing that it is complaining about. The question is: what do we do about this? One option, as I understand it, is to replace these casts with one of the C++-style casts (static_cast<...>, const_cast<...>, etc.). A second (better?) option is to use STL vectors. A third option is to just ignore this and proceed ahead.
I have to admit I don't understand at this point if the uninitialized member variable warnings are so-called "false positives" of cppcheck, or if there is some non-standard procedure that is being followed in our code.
The text was updated successfully, but these errors were encountered:
I started looking into using cppcheck to analyze source code. I started with the hcana/src directory, but of course this should be applied to the entire Hall A analyzer as well, in principle.
Cppcheck produced a lot of suggestions for improvement, which break down into several categories:
a) warnings about unused variables, etc.
b) potential performance hits
c) style issues
I took some time to fix a few of the things that showed up from categories a) and b) ... that was pretty simple. However, there remain to broad types of things that cppcheck complains about:
Below is the output of cppcheck from just one of the pieces of source code in hcana/src:
[src/THcAerogel.cxx:263]: (style) C-style pointer casting
[src/THcAerogel.cxx:267]: (style) C-style pointer casting
[src/THcAerogel.cxx:273]: (style) C-style pointer casting
[src/THcAerogel.cxx:279]: (style) C-style pointer casting
[src/THcAerogel.cxx:285]: (style) C-style pointer casting
[src/THcAerogel.cxx:305]: (style) C-style pointer casting
[src/THcAerogel.cxx:454]: (style) C-style pointer casting
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fPosGain' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fNegGain' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fA_Pos' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fA_Neg' is not initialized in the constructor.
... and so on.
Looking at the first few entries, the code looks like this:
.
.
while(ihit < fNhits) {
THcAerogelHit* hit = (THcAerogelHit *) fRawHitList->At(ihit);
.
.
So, you can see the type of thing that it is complaining about. The question is: what do we do about this? One option, as I understand it, is to replace these casts with one of the C++-style casts (static_cast<...>, const_cast<...>, etc.). A second (better?) option is to use STL vectors. A third option is to just ignore this and proceed ahead.
I have to admit I don't understand at this point if the uninitialized member variable warnings are so-called "false positives" of cppcheck, or if there is some non-standard procedure that is being followed in our code.
The text was updated successfully, but these errors were encountered: