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
8
votes
0 answers

SonarQube Coverage always 0%

Tools: SonarQube Server 6.0, Sonar Scanner 3.0.3, Jenkins running on a Linux Build Slave with pipeline format, CppuTest, gcovr, Bitbucket, git, JDK 8 Problem: The Coverage measure on the sonarqube server inexplicably show 0.0% coverage, and a…
8
votes
2 answers

Dynamic arrays: using realloc() without memory leaks

I use realloc to resize the memory allocated: char **get_channel_name(void) { char **result; int n; result = (char **) 0; for (elem = snd_mixer_first_elem(handle), n = 0; elem; elem = snd_mixer_elem_next(elem)) { if…
Cecylia
  • 349
  • 4
  • 12
8
votes
6 answers

How do I install Cppcheck using the tar file on Linux?

I'm trying to install Cppcheck via telnet on a Linux box. I have the cppcheck-1.67.tar file and I untar it. I don't see anything that will install it for me. Am I approaching this the correct way?
Tony Tran
  • 81
  • 1
  • 1
  • 2
8
votes
2 answers

How do i run a saved project from command line in CppCheck

I created a project in CppCheck named CppCheck_MainRls.cppcheck that includes several directories, i can run the project from the gui and it's working. my project is huge so i only need a few directories to pass through CppCheck and export the…
Mike Tishler
  • 183
  • 10
7
votes
2 answers

Disable or enable warnings for cppcheck using a configuration file

With clang-tidy static analyzer I can keep a file (.clang-tidy) in the root of the project with the warnings I want to activate or deactivate. clang-tidy will look for this file (as far I know) and use the options defined there. This saves me from…
alfC
  • 14,261
  • 4
  • 67
  • 118
7
votes
2 answers

cppcheck thinks I have "Redundant code: Found a statement that begins with numeric constant"

Cppcheck (version 1.46.1) gives the following warning for an enum like this one: enum DATABASE_TYPE { DATABASE_TYPE_UNKNOWN = -1, // <- line of warning DATABASE_TYPE_ORACLE, DATABASE_TYPE_MSACCESS }; Redundant code: Found a statement…
foraidt
  • 5,519
  • 5
  • 52
  • 80
7
votes
2 answers

How do I fix this error with allocation and deallocation mismatch?

Cppcheck report as an error "Mismatching allocation and deallocation: cname" for the line with delete cname;. I don't see what the problem with using my version of code is - it looks working. Is my code wrong? How do I fix it? And what are the…
abrahab
  • 2,430
  • 9
  • 39
  • 64
7
votes
3 answers

Why does Cppcheck not find this obvious array out-of-bounds error?

I installed the Cppcheck tool for static code analysis of my C++ project and got the feeling that it performs poorly. For example, can anyone tell me why Cppcheck is unable to find an array out-of-bounds error in the following code? void f(int c) {…
dokaspar
  • 8,186
  • 14
  • 70
  • 98
7
votes
3 answers

cannot generate XML output from cppcheck

I am using cppcheck for static analysis of C Code, but cannot seem to get an XML. I require the XML File to be consumed by Jenkins Here is what i have tried so far: runcppcheck.sh #!/bin/sh cd obj/msc cppcheck --enable=all -I. -I. -I. -I. -I. -I.…
kamal
  • 9,637
  • 30
  • 101
  • 168
6
votes
3 answers

C/C++ no curly brace after if/for, how to lint it out?

Is there way to get rid or find by linting (or maybe seding/regexping) these nasty situations when your have just one line of code after if/for statement, without curly braces? Like this one: if(condition) return; For reference why would I want…
M.K.
  • 89
  • 3
6
votes
2 answers

cppcheck warns about the pointer to local variable in list initialization

I analyzed some code with cppcheck for errors and code quality. I came across an error which I think is an false positive. The following code example shows the problem (marked with comment). cppcheck - v 1.89 #include #include…
skratchi.at
  • 1,151
  • 7
  • 22
6
votes
1 answer

Is the order of evaluation with comma operator & assignment in C predictable?

Recently cppcheck raised an error in some C code, that has the structure: ((void)(value_prev = value), value = new_value()) In most cases this can be split onto 2 lines, however there are some cases this is useful to have in a single statement. In…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
6
votes
3 answers

How to exclude test paths from cppcheck analysis?

I try to run a cppcheck analysis over my code, which has the following file structure: /code/module_1/src/a.cpp /code/module_1/src/b.cpp /code/module_1/test/c.cpp /code/module_2/src/d.cpp /code/module_2/src/e.cpp /code/module_3/test/f.cpp I'd like…
Martin
  • 71
  • 4
6
votes
1 answer

Why does CppCheck give an array access out of bounds error for this static const array?

CppCheck 1.67 has identified and array accessed out of bounds error on one of my projects. I didn't think the code was wrong, so I have stripped down the code to the bare minimum example that still raises the same error. Why does CppCheck give the…
6
votes
1 answer

What is a Windows equivalent of CppCheck?

I have an extreme problem. I have been working on a game for about two years(20000+ lines of code), and Lately I have been noticing a ton of memory leaks. The problem is that I cannot track every single one of them since my game is way too big... I…
Molma
  • 171
  • 9
1 2
3
25 26