Skip to content

Commit 54de32a

Browse files
committed
Merge branch 'chr_Fix12540_42' of https://github.com/chrchr-github/cppcheck into chr_Fix12540_42
2 parents ebc0d9f + 5ea8330 commit 54de32a

File tree

10 files changed

+206
-36
lines changed

10 files changed

+206
-36
lines changed

cfg/opencv2.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<noreturn>false</noreturn>
7070
<returnValue type="void"/>
7171
<arg nr="1">
72-
<not-uninit indirect="1"/>
72+
<not-uninit/>
7373
</arg>
7474
</function>
7575
<!-- void * cv::fastMalloc (size_t bufSize) -->

cfg/wxwidgets.cfg

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,35 @@
22
<def format="2">
33
<type-checks>
44
<unusedvar>
5-
<check>wxRect</check>
6-
<check>wxSize</check>
5+
<check>wxAcceleratorEntry</check>
6+
<check>wxArrayDouble</check>
7+
<check>wxArrayInt</check>
8+
<check>wxArrayPtrVoid</check>
9+
<check>wxArrayShort</check>
10+
<check>wxArrayString</check>
11+
<check>wxBrush</check>
12+
<check>wxColour</check>
13+
<check>wxDateSpan</check>
14+
<check>wxFileType</check>
15+
<check>wxFont</check>
16+
<check>wxFontInfo</check>
17+
<check>wxFontList</check>
18+
<check>wxPen</check>
19+
<check>wxPenList</check>
720
<check>wxPoint</check>
8-
<check>wxPoint2DInt</check>
921
<check>wxPoint2DDouble</check>
22+
<check>wxPoint2DInt</check>
23+
<check>wxPosition</check>
1024
<check>wxRealPoint</check>
11-
<check>wxVersionInfo</check>
1225
<check>wxRegion</check>
1326
<check>wxRegEx</check>
14-
<check>wxPosition</check>
15-
<check>wxFileType</check>
27+
<check>wxRect</check>
28+
<check>wxSize</check>
29+
<check>wxSystemOptions</check>
30+
<check>wxSystemSettings</check>
1631
<check>wxTimeSpan</check>
17-
<check>wxDateSpan</check>
18-
<check>wxAcceleratorEntry</check>
32+
<check>wxVector</check>
33+
<check>wxVersionInfo</check>
1934
</unusedvar>
2035
<operatorEqVarError>
2136
</operatorEqVarError>

lib/library.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,20 +1075,26 @@ bool Library::isuninitargbad(const Token *ftok, int argnr, int indirect, bool *h
10751075
/** get allocation info for function */
10761076
const Library::AllocFunc* Library::getAllocFuncInfo(const Token *tok) const
10771077
{
1078+
while (Token::simpleMatch(tok, "::"))
1079+
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
10781080
const std::string funcname = getFunctionName(tok);
10791081
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mAlloc, funcname);
10801082
}
10811083

10821084
/** get deallocation info for function */
10831085
const Library::AllocFunc* Library::getDeallocFuncInfo(const Token *tok) const
10841086
{
1087+
while (Token::simpleMatch(tok, "::"))
1088+
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
10851089
const std::string funcname = getFunctionName(tok);
10861090
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mDealloc, funcname);
10871091
}
10881092

10891093
/** get reallocation info for function */
10901094
const Library::AllocFunc* Library::getReallocFuncInfo(const Token *tok) const
10911095
{
1096+
while (Token::simpleMatch(tok, "::"))
1097+
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
10921098
const std::string funcname = getFunctionName(tok);
10931099
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mRealloc, funcname);
10941100
}

lib/symboldatabase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,11 +2558,11 @@ Function::Function(const Token *tok,
25582558
}
25592559

25602560
// class constructor/destructor
2561-
else if (((tokenDef->str() == scope->className) ||
2561+
else if (scope->isClassOrStructOrUnion() &&
2562+
((tokenDef->str() == scope->className) ||
25622563
(tokenDef->str().substr(0, scope->className.size()) == scope->className &&
25632564
tokenDef->str().size() > scope->className.size() + 1 &&
2564-
tokenDef->str()[scope->className.size() + 1] == '<')) &&
2565-
scope->type != Scope::ScopeType::eNamespace) {
2565+
tokenDef->str()[scope->className.size() + 1] == '<'))) {
25662566
// destructor
25672567
if (tokenDef->previous()->str() == "~")
25682568
type = Function::eDestructor;

lib/valueflow.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,15 +2200,11 @@ static void valueFlowReverse(const TokenList& tokenlist,
22002200
Token* tok,
22012201
const Token* const varToken,
22022202
ValueFlow::Value val,
2203-
const ValueFlow::Value& val2,
22042203
ErrorLogger* errorLogger,
22052204
const Settings& settings,
22062205
SourceLocation loc = SourceLocation::current())
22072206
{
2208-
std::list<ValueFlow::Value> values = {std::move(val)};
2209-
if (val2.varId != 0)
2210-
values.push_back(val2);
2211-
valueFlowReverse(tok, nullptr, varToken, std::move(values), tokenlist, errorLogger, settings, loc);
2207+
valueFlowReverse(tok, nullptr, varToken, {std::move(val)}, tokenlist, errorLogger, settings, loc);
22122208
}
22132209

22142210
static bool isConditionKnown(const Token* tok, bool then)
@@ -7639,7 +7635,6 @@ static void valueFlowSwitchVariable(const TokenList &tokenlist, const SymbolData
76397635
const_cast<Token*>(scope.classDef),
76407636
vartok,
76417637
*val,
7642-
ValueFlow::Value(),
76437638
errorLogger,
76447639
settings);
76457640
}

test/cfg/opencv2.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ void validCode(const char* argStr)
3030
cvStr += " World";
3131
std::cout << cvStr;
3232

33-
char * pBuf = (char *)cv::fastMalloc(20); // cppcheck-suppress cstyleCast
33+
// cppcheck-suppress [cstyleCast, unusedAllocatedMemory]
34+
char * pBuf = (char *)cv::fastMalloc(20);
3435
cv::fastFree(pBuf);
3536
}
3637

@@ -42,7 +43,9 @@ void ignoredReturnValue()
4243

4344
void memleak()
4445
{
45-
const char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
46-
std::cout << pBuf; // cppcheck-suppress valueFlowBailoutIncompleteVar
46+
// cppcheck-suppress cstyleCast
47+
const char * pBuf = (char *)cv::fastMalloc(1000);
48+
// cppcheck-suppress [uninitdata, valueFlowBailoutIncompleteVar]
49+
std::cout << pBuf;
4750
// cppcheck-suppress memleak
4851
}

test/cfg/std.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,7 +2928,7 @@ void uninitvar_longjmp(void)
29282928
void uninitvar_malloc(void)
29292929
{
29302930
size_t size;
2931-
// cppcheck-suppress [uninitvar, cstyleCast]
2931+
// cppcheck-suppress [uninitvar, cstyleCast, unusedAllocatedMemory]
29322932
int *p = (int*)std::malloc(size);
29332933
free(p);
29342934
}
@@ -4957,7 +4957,7 @@ void std_vector_data_arithmetic()
49574957

49584958
void memleak_std_malloc() // #12332
49594959
{
4960-
//cppcheck-suppress [unreadVariable, constVariablePointer]
4960+
//cppcheck-suppress [unreadVariable, constVariablePointer, unusedAllocatedMemory]
49614961
void* p = std::malloc(1);
49624962
//cppcheck-suppress memleak
49634963
}
@@ -4971,7 +4971,7 @@ void memleak_std_realloc(void* block, size_t newsize)
49714971

49724972
void unusedAllocatedMemory_std_free()
49734973
{
4974-
// TODO cppcheck-suppress unusedAllocatedMemory
4974+
// cppcheck-suppress unusedAllocatedMemory
49754975
void* p = std::malloc(1);
49764976
std::free(p);
49774977
}

test/cfg/wxwidgets.cpp

Lines changed: 156 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,177 @@
1212
#include <wx/wx.h>
1313
#include <wx/accel.h>
1414
#include <wx/app.h>
15-
#include <wx/dc.h>
16-
#include <wx/log.h>
17-
#include <wx/filefn.h>
18-
#include <wx/geometry.h>
19-
#include <wx/spinctrl.h>
2015
#include <wx/artprov.h>
16+
#include <wx/bitmap.h>
17+
#include <wx/brush.h>
2118
#include <wx/calctrl.h>
19+
#include <wx/colour.h>
2220
#include <wx/combo.h>
23-
#include <wx/icon.h>
24-
#include <wx/bitmap.h>
21+
#include <wx/dc.h>
2522
#include <wx/dataview.h>
2623
#include <wx/datetime.h>
27-
#include <wx/memory.h>
24+
#include <wx/dc.h>
25+
#include <wx/dynarray.h>
26+
#include <wx/filefn.h>
27+
#include <wx/font.h>
2828
#include <wx/frame.h>
29+
#include <wx/gdicmn.h>
30+
#include <wx/geometry.h>
31+
#include <wx/icon.h>
32+
#include <wx/log.h>
2933
#include <wx/menu.h>
34+
#include <wx/memory.h>
3035
#include <wx/mimetype.h>
36+
#include <wx/pen.h>
37+
#include <wx/position.h>
38+
#include <wx/propgrid/property.h>
3139
#include <wx/regex.h>
3240
#include <wx/region.h>
33-
#include <wx/stattext.h>
41+
#include <wx/settings.h>
42+
#include <wx/spinctrl.h>
3443
#include <wx/sizer.h>
3544
#include <wx/string.h>
45+
#include <wx/sysopt.h>
3646
#include <wx/textctrl.h>
37-
#include <wx/gdicmn.h>
38-
#include <wx/propgrid/property.h>
39-
#include <wx/position.h>
47+
#include <wx/vector.h>
4048
#include <wx/versioninfo.h>
4149

50+
void unusedVariable_wxSystemOptions()
51+
{
52+
// cppcheck-suppress unusedVariable
53+
wxSystemOptions a;
54+
}
55+
56+
void unusedVariable_wxSystemSettings()
57+
{
58+
// cppcheck-suppress unusedVariable
59+
wxSystemSettings a;
60+
}
61+
62+
void unusedVariable_wxPenList()
63+
{
64+
// cppcheck-suppress unusedVariable
65+
wxPenList a;
66+
}
67+
68+
void unusedVariable_wxPen(const wxColour &colour, int width, const wxPenStyle style, const wxPen &pen)
69+
{
70+
// cppcheck-suppress unusedVariable
71+
wxPen a;
72+
// cppcheck-suppress unreadVariable
73+
wxPen b(colour, width);
74+
// cppcheck-suppress unreadVariable
75+
wxPen c(colour, width, style);
76+
// cppcheck-suppress unreadVariable
77+
wxPen d(pen);
78+
}
79+
80+
void unusedVariable_wxBrush(const wxColour &color, const wxBrushStyle style, const wxBitmap &bmp, const wxBrush &brush)
81+
{
82+
// cppcheck-suppress unusedVariable
83+
wxBrush a;
84+
// cppcheck-suppress unreadVariable
85+
wxBrush b(color, style);
86+
// cppcheck-suppress unreadVariable
87+
wxBrush c(bmp);
88+
// cppcheck-suppress unreadVariable
89+
wxBrush d(brush);
90+
}
91+
92+
void unusedVariable_wxFontList()
93+
{
94+
// cppcheck-suppress unusedVariable
95+
wxFontList a;
96+
}
97+
98+
void unusedVariable_wxFontInfo(const double pointSize, const wxSize &sz)
99+
{
100+
// cppcheck-suppress unusedVariable
101+
wxFontInfo a;
102+
// cppcheck-suppress unreadVariable
103+
wxFontInfo b(pointSize);
104+
// cppcheck-suppress unreadVariable
105+
wxFontInfo c(sz);
106+
}
107+
108+
void unusedVariable_wxFont(const wxFont &font,
109+
const wxFontInfo &fontInfo,
110+
const int pointSize,
111+
const wxFontFamily family,
112+
const wxFontStyle style,
113+
const wxFontWeight weight,
114+
const bool underline,
115+
const wxString &faceName,
116+
const wxFontEncoding encoding)
117+
{
118+
// cppcheck-suppress unusedVariable
119+
wxFont a;
120+
// cppcheck-suppress unreadVariable
121+
wxFont b(font);
122+
// cppcheck-suppress unreadVariable
123+
wxFont c(fontInfo);
124+
// cppcheck-suppress unreadVariable
125+
wxFont d(pointSize, family, style, weight);
126+
// cppcheck-suppress unreadVariable
127+
wxFont e(pointSize, family, style, weight, underline);
128+
// cppcheck-suppress unreadVariable
129+
wxFont f(pointSize, family, style, weight, underline, faceName);
130+
// cppcheck-suppress unreadVariable
131+
wxFont g(pointSize, family, style, weight, underline, faceName, encoding);
132+
}
133+
134+
void unusedVariable_wxVector()
135+
{
136+
// cppcheck-suppress unusedVariable
137+
wxVector<int> a;
138+
}
139+
140+
void unusedVariable_wxArrayInt()
141+
{
142+
// cppcheck-suppress unusedVariable
143+
wxArrayInt a;
144+
}
145+
146+
void unusedVariable_wxArrayDouble()
147+
{
148+
// cppcheck-suppress unusedVariable
149+
wxArrayDouble a;
150+
}
151+
152+
void unusedVariable_wxArrayShort()
153+
{
154+
// cppcheck-suppress unusedVariable
155+
wxArrayShort a;
156+
}
157+
158+
void unusedVariable_wxArrayString()
159+
{
160+
// cppcheck-suppress unusedVariable
161+
wxArrayString a;
162+
}
163+
164+
void unusedVariable_wxArrayPtrVoid()
165+
{
166+
// cppcheck-suppress unusedVariable
167+
wxArrayPtrVoid a;
168+
}
169+
170+
void unreadVariable_wxColour(const unsigned char uc, const wxString &name, const unsigned long colRGB, const wxColour &colour)
171+
{
172+
// cppcheck-suppress unusedVariable
173+
wxColour a;
174+
// cppcheck-suppress unreadVariable
175+
wxColour b(uc, uc, uc);
176+
// cppcheck-suppress unreadVariable
177+
wxColour c(uc, uc, uc, uc);
178+
// cppcheck-suppress unreadVariable
179+
wxColour d(name);
180+
// cppcheck-suppress unreadVariable
181+
wxColour e(colRGB);
182+
// cppcheck-suppress unreadVariable
183+
wxColour f(colour);
184+
}
185+
42186
void unreadVariable_wxPoint2DInt(const wxInt32 x, const wxPoint2DInt& pti, const wxPoint &pt)
43187
{
44188
// cppcheck-suppress unusedVariable
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
o oo(){extern oo();}

test/testsymboldatabase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,12 @@ class TestSymbolDatabase : public TestFixture {
22392239
ASSERT(db && ctor && ctor->type == Function::eMoveConstructor);
22402240
ASSERT(ctor && ctor->retDef == nullptr);
22412241
}
2242+
{
2243+
GET_SYMBOL_DB("void f() { extern void f(); }");
2244+
ASSERT(db && db->scopeList.size() == 2);
2245+
const Function* f = findFunctionByName("f", &db->scopeList.back());
2246+
ASSERT(f && f->type == Function::eFunction);
2247+
}
22422248
}
22432249

22442250
void functionDeclarationTemplate() {

0 commit comments

Comments
 (0)