0

I am running static code analysis using cppcheck.

I have a cpp source file which as bugs like "null pointer dereferenced" etc.

There is a piece of code in file. A structure is declared inside a class

class Example{
    public:
        typedef struct {
            int num;
        }MyStruct;
};

When array of structure is declared

Example::MyStruct st_arr[5];

Cppcheck stops the analysis as soon as it reaches this code and doesn't go further and report other bugs in file.

But if I simply declare a struct variable

Example::MyStruct st;

It goes fine.

So, the cppcheck stops the analysis when array of struct (declared in a class) is created. Is this a issue with cppcheck?

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • I think that you library headers will be included in your program, so that cppcheck showing you errors. And it seems like you are using some buggy library you'd better to change to something else. – Victor Gubin Mar 27 '18 at 07:58
  • I am not including any system headers or any 3rd party library. – Ranjan Kumar Mar 27 '18 at 08:12
  • :) So why don't you start to fix issues in your header file then :) If you don't know how - read Scott Meyers Effective C++. Scott explaining things, cppcheck automatically detected, and how to fix them. – Victor Gubin Mar 27 '18 at 08:18
  • Thanks, but we have legacy code it has very large code base, so we are ignoring all the style errors, we only want to consider bugs. – Ranjan Kumar Mar 27 '18 at 08:22

2 Answers2

0

Most static analysis tools can be configured to not report errors from library headers. You probably have to configure cppcheck to recognize the headers, e.g. by defining paths which are treated as library files. They also usually parse special comments in the source code which can be used to suppress errors in regions of code, e.g. suppress errors before the include and then re-enable afterwards. How this works is described in the documentation of the tools.

These tools also have the ability to define suppressions to discard errors, e.g. false positives. This can also be used to suppress errors from third-party code.

The cppcheck manual chapters "Chapter 8. Suppressions" and "Chapter 9. Library configuration" should explain how to do this. If you have specific problems with the configuration you can post more detailed questions.

Jens
  • 9,058
  • 2
  • 26
  • 43
0

I am a Cppcheck developer.

I see such weird behaviour also. It is not by intention. I will investigate.

Best regards, Daniel Marjamäki

Daniel Marjamäki
  • 2,907
  • 15
  • 16