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.

331 questions
36
votes
3 answers

How to use CMAKE_EXPORT_COMPILE_COMMANDS?

I've been trying to use clang-modernize with CMAKE_EXPORT_COMPILE_COMMANDS as recommended in the help of this tool. With this option cmake generates a JSON file containing compile info like include paths (see also). This variable is accepted on the…
dzada
  • 4,148
  • 5
  • 23
  • 35
34
votes
3 answers

Rulesets for cppcheck

Cppcheck allows you to create your own rules files, but I don't know how much of cppcheck's functionality is exposed. Is anyone working on a set that would enforce JSF or MISRA rules?
Martin Beckett
  • 90,457
  • 25
  • 178
  • 252
33
votes
7 answers

c++, usleep() is obsolete, workarounds for Windows/MingW?

I already found out with another question that Windows/MingW doesn't provide the nanosleep() and setitimer() alternatives to the obsolete usleep(). But my goal is to fix all warnings that cppcheck gives me, including the usleep() style warnings. So,…
blubberbernd
  • 3,291
  • 7
  • 30
  • 44
28
votes
4 answers

How to use cppcheck's inline suppression filter option for C++ code?

I would like to use Cppcheck for static code analysis of my C++ code. I learned that I can suppress some kind of warnings with --inline-suppr command. However, I can't find what "suppressed_error_id" I should put in the comment: //…
Blaise
  • 6,244
  • 4
  • 38
  • 53
25
votes
2 answers

cppcheck can't find include files

cppcheck can't find even standard headers such as iostream. Any ideas? I am using Ubuntu 11.04 and cppcheck from the repository.
pic11
  • 12,658
  • 17
  • 74
  • 108
23
votes
1 answer

Recommended way to track down array out-of-bound access/write in C program

Consider writing implementation for some not-so-obvious algorithm in C. For example let it be recursive quicksort, that I have found in K. N. King's "C Programming: A Modern Approach, 2nd Edition" book, that it's available from here. The most…
Grzegorz Szpetkowski
  • 35,042
  • 4
  • 82
  • 127
21
votes
2 answers

being sure about "unknown evaluation order"

Since version 1.80, Cppcheck tells me that Expression 'msg[ipos++]=checksum(&msg[1],ipos-1)' depends on order of evaluation of side effects in this code sequence (simplified, data is a variable) BYTE msg[MAX_MSG_SIZE]; // msg can be smaller,…
Wolf
  • 8,482
  • 7
  • 48
  • 92
21
votes
6 answers

cppcheck std.cfg not found error when std.cfg file is available

If i launch my cppcheck i get following error: cppcheck ListLib.c (information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled with CFGDIR set to "/usr/bin/cfg" and will therefore…
zilleplus
  • 427
  • 1
  • 3
  • 11
20
votes
1 answer

Cppcheck support in CMake

I am not asking about the various available third-party modules that support Cppcheck in one way or the other. With CMake 3.10, CMake seems to have gained some official Cppcheck support. See CMAKE__CPPCHECK. Unfortunately the documentation how…
arved
  • 3,830
  • 3
  • 23
  • 47
18
votes
3 answers

Cppcheck: how to skip a directory of third party header files?

I call cppcheck on our own files in our source base. However, some source files include header files from third party libraries, say from ./lib/some_library/. These are automatically parsed by cppcheck as well. I don't want this, since I don't want…
Chiel ten Brinke
  • 12,091
  • 12
  • 60
  • 104
16
votes
1 answer

Is there a list of Cppcheck messages?

Our team previously used Lint as a static code analyser, but it became too cluttered and had too much noise. We are using C++03 with frequent use of Boost, and Lint didn't seem to like Boost (I hear this has become better in later versions). I…
Tas
  • 6,589
  • 3
  • 31
  • 47
14
votes
1 answer

cppcheck throws warning on const std::string[]

I'm struggling with a warning that cppcheck (version 1.85 on a Linux machine) is reporting: someFile.h:23:29: warning: Redundant code: Found a statement that begins with string constant. [constStatement] const std::string OffOn[]= {"off", "on"}; …
Mukuma
  • 143
  • 5
14
votes
2 answers

Should I use rand() or rand_r()?

I'm trying to get a random number in C++ and I'm using rand(). This is what cpplint says: Consider using rand_r(...) instead of rand(...) for improved thread safety. I'm switching to rand_r and this is what cppcheck says: Obsolete function…
Barbara Krein
  • 299
  • 2
  • 7
13
votes
1 answer

How to prevent returning a pointer to a temporary variable?

On a recent bug hunt, I found an issue with returning a pointer to a member of a temporary variable. The offending (simplified) code was: struct S { S(int i) : i(i) {} int i; int* ptr() { return &i; } }; int* fun(int i) { return…
12
votes
2 answers

How to find C++ spurious copy operations?

Recently, I had the following struct data { std::vector V; }; data get_vector(int n) { std::vector V(n,0); return {V}; } The problem with this code is that when the struct is created a copy occurs and the solution is instead to…
1
2 3
22 23