Questions tagged [cppcheck]

Cppcheck is an open source tool for static C/C++ code analysis that tries to detect bugs that a C/C++ compiler doesn't see.

Cppcheck - A tool for static C/C++ code analysis

Cppcheck is an analysis tool for C/C++ code. Unlike C/C++ compilers and many other analysis tools, we don't detect syntax errors. Cppcheck only detects the types of bugs that the compilers normally fail to detect. The goal is no false positives.

389 questions
0
votes
0 answers

how can i execute CppCheck with Cmake on specific directories

Hi im using google test libraire on my project and i want launch cppecheck with cmake on src and test folders only this my Project structure ---Project --src --test and google test will generate on builded folder find_program(CMAKE_CXX_CPPCHECK …
0
votes
2 answers

how get count of parent Directories from zip (Compressed) file in qt c++?

Im new in qt. I use quazip for compress a folder and it compressed successfully. But now if i want to know how many parents dir is available in unknown zip? how can i get count of parent dir from zip file? before unzip. please help me to get count…
0
votes
0 answers

cppcheck does not ignore espressif library files when run through jenkins pipeline

I would like to do the static analysis only of my project files, because the third-party library is usually dockerized and stable, it is not necessary to perform the static analysis every time of something immutable, but I am having some problems…
0
votes
3 answers

Is it unsafe to take the address of a variable inside a loop where it is defined?

I came across a comment in cppcheck source code here, stating that it is unsafe to move the definition of i in the example into the inner loop. Why is that? void CheckOther::variableScopeError(const Token *tok, const std::string &varname) { …
Moberg
  • 5,253
  • 4
  • 38
  • 54
0
votes
0 answers

How to share a folder from container A to container B?

I illustrated my problem through a diagram to complement my explanations: To contextualize, I'm working with continuous integration, I have a host machine with jenkins running on that, and then through the script pipeline will execute containers A…
0
votes
0 answers

How can i add new rules to cppcheclipse?

I am using the cppcheclipse version i downloaded from here: https://github.com/kwin/cppcheclipse/releases/ I want to add new rules but i can't find where the rules file is. There is this…
0
votes
1 answer

cppcheck: one definition rule is violated when overriding

In the following code (which is a minimal example based on a much more complex code), a base class defines a struct local to the class. A derived class overrides this definition, but uses also the definition in the base class. #include…
francesco
  • 7,189
  • 7
  • 22
  • 49
0
votes
2 answers

can anyone explain why my code gets runtime error in cpp?

Can anyone solve this runtime error? Status :Time limit exceeded Time: 5 secs Memory: 5.368 Mb Input 4 8 4 1 2 1 2 5 3 5 1 3 4 1 2 4 5 11 1 1 1 3 12 Runtime Error SIGTSTP #include using namespace std; int main() { // your code…
pooaraz
  • 3
  • 1
0
votes
1 answer

cppcheck throws syntaxError with #ifdef

I have a file that can be summarized as shown below. namespace MyNamespace { #if defined(SOME_UNSET_CONDITION) TEST_CASE("STR1", "[STR2]") { } TEST_CASE("STR3", "[STR4]") { } #endif } When calling Cppcheck v2.8 on the file, the following is…
mitchute
  • 389
  • 1
  • 3
  • 10
0
votes
1 answer

cppcheck: member variable not initialized in the constructor

The following code, as far as I can tell, correctly initializes the variables of the derived class B: #include struct A { int i; }; struct B : A { int j; explicit B(A&& a) : A(std::move(a)), j{i} { } }; int main() { A a{3}; B…
francesco
  • 7,189
  • 7
  • 22
  • 49
0
votes
1 answer

Either the condition fp==NULL is redundant or there is a possible null pointer dereference

I get the above error in CppCheck but I can't see what's wrong.I guess the error is the reason my code doesn't find any files,even if they exist in my computer.Any help is appreciated. #include #include #include…
Jim
  • 9
  • 2
0
votes
2 answers

Resource leak or false positive

I have a code like this: std::string getInfo(FILE *fp) { char buffer[30]; if (fread(buffer, 19, 1, fp) == 1) buffer[19] = '\0'; else buffer[0] = '\0'; return buffer; } I'm using cppcheck for static analysis and it…
Milan Babuškov
  • 59,775
  • 49
  • 126
  • 179
0
votes
0 answers

warning : assignment from incompatible pointer type ( in Delete function)

Below are two structures viz Stu and Class. I have declared array of pointers of type Class in main and passing that to Delete function so that I can deallocate the memory(using free). When I compile this code it shows same warning on many lines…
0
votes
2 answers

cppcheck suggests to reduce scope of variable, should I?

So I have something like this int age; for (auto person : persons) { age = std::stoi(person[0]); /* Do other stuff with age in this loop*/ } Other than style, are there any performance benefits to declaring int age =…
Lord of Grok
  • 323
  • 3
  • 12
0
votes
1 answer

cppcheck: error: unrecognized command line option: "--file-filter

I am developing C code on Ubuntu 20.04. By running cppcheck -q --project=build/proj1/compile_commands.json --file-filter='src/base/Myfile.c' I got the error cppcheck: error: unrecognized command line option: "--file-filter=src/base/Myfile.c".
Barzi2001
  • 989
  • 8
  • 24