cppcheck

CPPcheck html report

和自甴很熟 提交于 2019-12-24 05:30:16
问题 I have a question is there any way to generate one html file from few xml using cppcheck-htmlreport? Normally I doing that: /cppcheck-htmlreport --file /vobs/stn/dev/linux/cppcheck/xmlreport_v1.xml --title "xml1 test" --report-dir . Now I want to do something like this /cppcheck-htmlreport --file /vobs/stn/dev/linux/cppcheck/*.xml --title "xml1 test" --report-dir . But when I did that commend cppcheck convert only one xml file... Can anybody help me? I'm sorry for my weak english. 回答1: Did

c++ Possible null pointer dereference

≯℡__Kan透↙ 提交于 2019-12-22 08:26:15
问题 I ran cppcheck over some code to look for possible runtime errors. And it is reporting a possible null pointer dereference with the following situation: Foo* x = ... //defined somewhere ... Foo* y(x); //possible null pointer dereference. Edit: Better example for( int i = 0; i < N; i++ ) { Foo* x( ArrayOfObjsContainingFooPtr[i].FooPtr ); // line 3 if( !x ) // line 4 continue; } Error message from cppcheck: [C:\file.cpp:3]: (error) Possible null pointer dereference: x - otherwise it is

Dynamic arrays: using realloc() without memory leaks

余生长醉 提交于 2019-12-18 06:17:21
问题 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 (!snd_mixer_selem_is_active(elem)) continue; if (snd_mixer_selem_has_playback_volume(elem) && snd_mixer_selem_has_playback_switch(elem) && snd_mixer_selem_has_capture_switch(elem)) { if (result == (char **) 0) result = (char **) malloc(sizeof(char *)); else result = (char **)

Cppcheck support in CMake

一曲冷凌霜 提交于 2019-12-17 18:37:36
问题 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_<LANG>_CPPCHECK. Unfortunately the documentation how to use this variable is a bit sparse. Is there a good example of how Cppcheck is supposed to be used with CMake 3.10 (or later)? 回答1: An simple example would be - if you have cppcheck in your PATH and you are not specifying additional parameters -

Sending Cppcheck result/report on email from Jenkins using email-ext plugin

[亡魂溺海] 提交于 2019-12-13 17:22:21
问题 I'm trying to send cppcheck report on an email using email-ext plugin from a Jenkins build. So far, only way seems to be by creating a custom template -- jelly or groovy. From this post -- "Can I configure jenkins to send an email with a static analysis report summary?" -- it looks like I should be able to instantiate CppcheckBuildAction and use its methods but for some reason, it doesn't seem to instantiate (ie. the object is null). Here's the code I've put in the jelly template to check

What is cppcheck rule-file <pattern> syntax?

爱⌒轻易说出口 提交于 2019-12-13 00:39:21
问题 I've poked around for a while, and can't find this anywhere. I have found a nice example of a cppcheck rule-file that shows a simple pattern; <?xml version="1.0"?> <rule version="1"> <pattern>if \( p \) { free \( p \) ; }</pattern> <message> <id>redundantCondition</id> <severity>style</severity> <summary>Redundant condition. It is valid to free a NULL pointer.</summary> </message> </rule> Which works nicely, as long as all the pointers are named 'p' and the call is 'free'. How do I change 'p'

Null Pointer Dereference issue not detected when the pointer is returned by another function

陌路散爱 提交于 2019-12-12 12:09:36
问题 I use SonarQube (5.1 with cppecheck 1.70) to analyse C-code. In following example, there is a Null Pointer Dereference issue that should be detected by SonarQube and/or Cppcheck (used by Sonar). But no issue found by SonarQube niether repported by Cppcheck. struct s1 { char c1; char c2; }; struct s1 * toto1(void) { return NULL; } void toto2(void) { struct s1* my_st=NULL; my_st = toto1(); my_st->c1 = 1; my_st->c2 = 0; return; } Is there any restriction on this rule (Null pointers should not be

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

本小妞迷上赌 提交于 2019-12-12 10:37:50
问题 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 that begins with numeric constant I don't think, that it's redundant. It's quite important to be able to do things like that. Is this an error of cppcheck or am I not seeing something? Update I managed to boil it down to a minimal example. This was complicated by

make cppcheck skip the PACKAGE definition

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:58:03
问题 I'm using the GUI version of cppcheck 1.64 for static code analysis on C++-Builde-6 code. For DLL exports and imports, the definition of PACKAGE is necessary: /// A dialog exported from a BPL (a VCL-specific kind of DLL) class PACKAGE MySharedDialog { public: // lots of methods to-be checked private: // lots of methods to-be checked // lots of members }; Cppcheck stops when it encounters PACKAGE because it doesn't know what it means: The code 'class PACKAGE TAppInfoDialog {' is not handled.

How can I tell Cppcheck to skip a header file

隐身守侯 提交于 2019-12-10 16:52:56
问题 Cppcheck scans all files in a project folder: c:\projectfolder\main.c c:\projectfolder\file.c c:\projectfolder\file.h c:\projectfolder\file_test.cc c:\projectfolder\file_test.cc contains the following code #include "c:/gtest/gtest.h" extern "C" { #include "TMyStruct.h" } TEST(Stack, Overflow) { TMyStruct unterTest; EXPECT_EQ(1, TMyStruct_Init(&unterTest)); EXPECT_GE(unterTest.variable, 9000); } File file_test.cc includes the gtest.h file C:\gtest\gtest.h All files in C:\gtest\ should not be