Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address various suggestions for improvement from cppcheck output #27

Open
brash99 opened this issue Nov 13, 2013 · 0 comments
Open

Address various suggestions for improvement from cppcheck output #27

brash99 opened this issue Nov 13, 2013 · 0 comments
Assignees

Comments

@brash99
Copy link
Contributor

brash99 commented Nov 13, 2013

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:

  1. C-style pointer casting
  2. 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:

.
.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant