Skip to content

Commit ac9d650

Browse files
authored
Merge branch 'cppcheck-opensource:main' into main
2 parents ea745c0 + 530e59f commit ac9d650

13 files changed

Lines changed: 225 additions & 12 deletions

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ test/testmathlib.o: test/testmathlib.cpp lib/check.h lib/checkers.h lib/color.h
844844
test/testmemleak.o: test/testmemleak.cpp lib/check.h lib/checkers.h lib/checkimpl.h lib/checkmemoryleak.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
845845
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testmemleak.cpp
846846

847-
test/testnullpointer.o: test/testnullpointer.cpp lib/check.h lib/checkers.h lib/checkimpl.h lib/checknullpointer.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
847+
test/testnullpointer.o: test/testnullpointer.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/checkers.h lib/checkimpl.h lib/checknullpointer.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h test/fixture.h test/helpers.h
848848
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testnullpointer.cpp
849849

850850
test/testoptions.o: test/testoptions.cpp lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/refthunk.h lib/settings.h lib/standards.h lib/utils.h test/fixture.h test/options.h

‎addons/cppcheckdata.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ class Suppression:
997997
errorId The id string of the error to suppress, can be a wildcard
998998
fileName The name of the file to suppress warnings for, can include wildcards
999999
lineNumber The number of the line to suppress warnings from, can be 0 to represent any line
1000+
thisAndNextLine Set if the line after lineNumber is suppressed too
10001001
symbolName The name of the symbol to match warnings for, can include wildcards
10011002
lineBegin The first line to suppress warnings from
10021003
lineEnd The last line to suppress warnings from
@@ -1006,6 +1007,7 @@ class Suppression:
10061007
errorId = None
10071008
fileName = None
10081009
lineNumber = None
1010+
thisAndNextLine = None
10091011
symbolName = None
10101012
lineBegin = None
10111013
lineEnd = None
@@ -1015,13 +1017,14 @@ def __init__(self, element):
10151017
self.errorId = element.get('errorId')
10161018
self.fileName = element.get('fileName')
10171019
self.lineNumber = element.get('lineNumber')
1020+
self.thisAndNextLine = element.get('thisAndNextLine')
10181021
self.symbolName = element.get('symbolName')
10191022
self.lineBegin = element.get('lineBegin')
10201023
self.lineEnd = element.get('lineEnd')
10211024
self.suppressionType = element.get('type')
10221025

10231026
def __repr__(self):
1024-
attrs = ["errorId", "fileName", "lineNumber", "symbolName", "lineBegin", "lineEnd","suppressionType"]
1027+
attrs = ["errorId", "fileName", "lineNumber", "thisAndNextLine", "symbolName", "lineBegin", "lineEnd","suppressionType"]
10251028
return "{}({})".format(
10261029
"Suppression",
10271030
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
@@ -1031,7 +1034,7 @@ def isMatch(self, file, line, message, errorId):
10311034
# Line Suppression
10321035
if ((self.fileName is None or fnmatch(file, self.fileName))
10331036
and (self.suppressionType is None) # Verify use of default suppression type (None = unique)
1034-
and (self.lineNumber is not None and int(line) == int(self.lineNumber))
1037+
and (self.lineNumber is not None and (int(line) == int(self.lineNumber) or (self.thisAndNextLine and int(line) == int(self.lineNumber) + 1)))
10351038
and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*'))
10361039
and fnmatch(errorId, self.errorId)):
10371040
return True
@@ -1052,6 +1055,7 @@ def isMatch(self, file, line, message, errorId):
10521055
# Other Suppression (Globally set via suppression file or cli command)
10531056
if ((self.fileName is None or fnmatch(file, self.fileName))
10541057
and (self.suppressionType is None)
1058+
and (self.lineNumber is None)
10551059
and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*'))
10561060
and fnmatch(errorId, self.errorId)):
10571061
return True

‎cfg/gtk.cfg‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,13 @@
336336
<define name="G_FILE_ATTRIBUTE_TRASH_ORIG_PATH" value="&quot;trash::orig-path&quot;"/>
337337
<define name="G_FILE_ATTRIBUTE_TRASH_DELETION_DATE" value="&quot;trash::deletion-date&quot;"/>
338338
<define name="G_FILE_ATTRIBUTE_RECENT_MODIFIED" value="&quot;recent::modified&quot;"/>
339-
<memory>
339+
<resource>
340340
<alloc init="true" no-fail="true">g_thread_new</alloc>
341341
<alloc init="true" no-fail="false">g_thread_try_new</alloc>
342342
<use>g_thread_ref</use>
343343
<dealloc>g_thread_unref</dealloc>
344344
<dealloc>g_thread_join</dealloc>
345-
</memory>
345+
</resource>
346346
<memory>
347347
<alloc init="true" no-fail="true">g_variant_iter_copy</alloc>
348348
<alloc init="true" no-fail="true">g_variant_iter_new</alloc>
@@ -8387,9 +8387,52 @@
83878387
<leak-ignore/>
83888388
<noreturn>false</noreturn>
83898389
</function>
8390+
<!-- GThread * g_thread_new (const gchar *name, GThreadFunc func, gpointer data); -->
8391+
<function name="g_thread_new">
8392+
<noreturn>false</noreturn>
8393+
<returnValue type="GThread *"/>
8394+
<use-retval/>
8395+
<arg nr="1" direction="in">
8396+
<not-uninit/>
8397+
</arg>
8398+
<arg nr="2" direction="in">
8399+
<not-null/>
8400+
<not-uninit/>
8401+
</arg>
8402+
<arg nr="3"/>
8403+
</function>
8404+
<!-- GThread * g_thread_try_new (const gchar *name, GThreadFunc func, gpointer data, GError **error); -->
8405+
<function name="g_thread_try_new">
8406+
<noreturn>false</noreturn>
8407+
<returnValue type="GThread *"/>
8408+
<use-retval/>
8409+
<arg nr="1" direction="in">
8410+
<not-uninit/>
8411+
</arg>
8412+
<arg nr="2" direction="in">
8413+
<not-null/>
8414+
<not-uninit/>
8415+
</arg>
8416+
<arg nr="3"/>
8417+
<arg nr="4" direction="out"/>
8418+
</function>
8419+
<!-- gpointer g_thread_join (GThread *thread); -->
83908420
<function name="g_thread_join">
8391-
<leak-ignore/>
83928421
<noreturn>false</noreturn>
8422+
<returnValue type="gpointer"/>
8423+
<arg nr="1">
8424+
<not-null/>
8425+
<not-uninit/>
8426+
</arg>
8427+
</function>
8428+
<!-- void g_thread_unref (GThread *thread); -->
8429+
<function name="g_thread_unref">
8430+
<noreturn>false</noreturn>
8431+
<returnValue type="void"/>
8432+
<arg nr="1">
8433+
<not-null/>
8434+
<not-uninit/>
8435+
</arg>
83938436
</function>
83948437
<function name="g_thread_pool_get_max_threads">
83958438
<leak-ignore/>

‎lib/calculate.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,43 +60,53 @@ R calculate(const std::string& s, const T& x, const T& y, bool* error = nullptr)
6060
constexpr MathLib::bigint maxBitsSignedShift = maxBitsShift - 1;
6161
switch (MathLib::encodeMultiChar(s)) {
6262
case '+':
63+
case '+=':
6364
return wrap(x + y);
6465
case '-':
66+
case '-=':
6567
return wrap(x - y);
6668
case '*':
69+
case '*=':
6770
return wrap(x * y);
6871
case '/':
72+
case '/=':
6973
if (isZero(y) || (std::is_signed<T>{} && y < 0)) {
7074
if (error)
7175
*error = true;
7276
return R{};
7377
}
7478
return wrap(x / y);
7579
case '%':
80+
case '%=':
7681
if (isZero(MathLib::bigint(y)) || (std::is_signed<T>{} && MathLib::bigint(y) < 0)) {
7782
if (error)
7883
*error = true;
7984
return R{};
8085
}
8186
return wrap(MathLib::bigint(x) % MathLib::bigint(y));
8287
case '&':
88+
case '&=':
8389
return wrap(MathLib::bigint(x) & MathLib::bigint(y));
8490
case '|':
91+
case '|=':
8592
return wrap(MathLib::bigint(x) | MathLib::bigint(y));
8693
case '^':
94+
case '^=':
8795
return wrap(MathLib::bigint(x) ^ MathLib::bigint(y));
8896
case '>':
8997
return wrap(x > y);
9098
case '<':
9199
return wrap(x < y);
92100
case '<<':
101+
case '<<=':
93102
if (y >= maxBitsSignedShift || y < 0 || x < 0) {
94103
if (error)
95104
*error = true;
96105
return R{};
97106
}
98107
return wrap(MathLib::bigint(x) << MathLib::bigint(y));
99108
case '>>':
109+
case '>>=':
100110
if (y >= maxBitsSignedShift || y < 0 || x < 0) {
101111
if (error)
102112
*error = true;

‎lib/ctu.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ std::string CTU::FileInfo::FunctionCall::toXmlString() const
124124
std::string CTU::FileInfo::NestedCall::toXmlString() const
125125
{
126126
std::ostringstream out;
127-
out << "<function-call"
127+
out << "<nested-call"
128128
<< toBaseXmlString()
129129
<< " " << ATTR_MY_ID << "=\"" << myId << "\""
130130
<< " " << ATTR_MY_ARGNR << "=\"" << myArgNr << "\""

‎lib/suppressions.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ void SuppressionList::dump(std::ostream & out, const std::string& filePath) cons
609609
out << " fileName=\"" << ErrorLogger::toxml(suppression.fileName) << '"';
610610
if (suppression.lineNumber != Suppression::NO_LINE)
611611
out << " lineNumber=\"" << suppression.lineNumber << '"';
612+
if (suppression.thisAndNextLine)
613+
out << " thisAndNextLine=\"true\"";
612614
if (!suppression.symbolName.empty())
613615
out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"';
614616
if (suppression.hash > 0)

‎lib/vf_settokenvalue.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ namespace ValueFlow
486486
}
487487

488488
// Calculations..
489-
else if ((parent->isArithmeticalOp() || parent->isComparisonOp() || (parent->tokType() == Token::eBitOp) ||
489+
else if ((parent->isArithmeticalOp() || parent->isComparisonOp() || (parent->tokType() == Token::eBitOp) || (Token::Match(parent, "%assign%") && parent->str().size() > 1) ||
490490
(parent->tokType() == Token::eLogicalOp)) &&
491491
parent->astOperand1() && parent->astOperand2()) {
492492

‎test/addon/test_cppcheckdata.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,17 @@ def test_line_suppression(self):
771771
assert supp.isMatch('a.c', '5', 'msg', 'zerodiv')
772772
assert not supp.isMatch('a.c', '5', 'msg', 'nullPointer')
773773

774-
@pytest.mark.xfail(strict=False,
775-
reason='the "other suppression" fallback in Suppression.isMatch() does not check '
776-
'that lineNumber is unset, so a line suppression matches every line')
777774
def test_line_suppression_other_line(self):
778775
supp = self.make_suppression(errorId='zerodiv', lineNumber='5')
779776
assert not supp.isMatch('a.c', '6', 'msg', 'zerodiv')
780777

778+
def test_line_suppression_this_and_next_line(self):
779+
supp = self.make_suppression(errorId='zerodiv', lineNumber='5', thisAndNextLine='true')
780+
assert supp.isMatch('a.c', '5', 'msg', 'zerodiv')
781+
assert supp.isMatch('a.c', '6', 'msg', 'zerodiv')
782+
assert not supp.isMatch('a.c', '4', 'msg', 'zerodiv')
783+
assert not supp.isMatch('a.c', '7', 'msg', 'zerodiv')
784+
781785
def test_wildcard_errorId(self):
782786
supp = self.make_suppression(errorId='*', lineNumber='5')
783787
assert supp.isMatch('a.c', '5', 'msg', 'anything')
@@ -821,7 +825,8 @@ def test_dumpfile_suppressions(self, dump_factory):
821825
location = cppcheckdata.Location({'file': supp.fileName, 'line': '5', 'column': '5'})
822826
assert cppcheckdata.is_suppressed(location, 'msg', 'uninitvar')
823827
assert not cppcheckdata.is_suppressed(location, 'msg', 'nullPointer')
824-
# NOTE: a non-matching line is not checked here - see test_line_suppression_other_line
828+
location = cppcheckdata.Location({'file': supp.fileName, 'line': '6', 'column': '5'})
829+
assert not cppcheckdata.is_suppressed(location, 'msg', 'uninitvar')
825830

826831

827832
class TestPureHelpers:

‎test/cfg/gtk.c‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,3 +777,57 @@ void g_idle_add_freed_data_test(void)
777777
// TODO cppcheck-suppress deallocuse
778778
g_idle_add(source_func_frees_data, data);
779779
}
780+
781+
static gpointer thread_func(gpointer data)
782+
{
783+
return data;
784+
}
785+
786+
void g_thread_join_releases_thread_test(void)
787+
{
788+
GThread *thread = g_thread_new("test", thread_func, NULL);
789+
g_thread_join(thread);
790+
791+
GThread *thread_try = g_thread_try_new("test", thread_func, NULL, NULL);
792+
if (thread_try)
793+
g_thread_join(thread_try);
794+
}
795+
796+
// Creating a thread has side effects, so a thread that is only released is
797+
// not unused.
798+
void g_thread_unref_detaches_thread_test(void)
799+
{
800+
GThread *thread = g_thread_new("test", thread_func, NULL);
801+
g_thread_unref(thread);
802+
}
803+
804+
void g_thread_join_parameter_test(GThread *thread)
805+
{
806+
g_thread_join(thread);
807+
}
808+
809+
// The thread function gets the data as a non-const gpointer.
810+
void g_thread_data_test(int *data)
811+
{
812+
GThread *thread = g_thread_new("test", thread_func, data);
813+
g_thread_join(thread);
814+
815+
GThread *thread_try = g_thread_try_new("test", thread_func, data, NULL);
816+
if (thread_try)
817+
g_thread_join(thread_try);
818+
}
819+
820+
void g_thread_not_joined_test(void)
821+
{
822+
GThread *thread = g_thread_new("test", thread_func, NULL);
823+
(void)thread;
824+
// cppcheck-suppress resourceLeak
825+
}
826+
827+
void g_thread_joined_twice_test(void)
828+
{
829+
GThread *thread = g_thread_new("test", thread_func, NULL);
830+
g_thread_join(thread);
831+
// cppcheck-suppress doubleFree
832+
g_thread_join(thread);
833+
}

‎test/cli/dumpfile_test.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,22 @@ def test_line_macro(tmpdir):
146146
with open(dumpfile, 'rt') as f:
147147
dump = f.read()
148148
assert 'type="number" isInt="true" macroName="__LINE__"' in dump
149+
150+
151+
def test_suppression_this_and_next_line(tmpdir):
152+
test_file = str(tmpdir / 'test.c')
153+
with open(test_file, 'wt') as f:
154+
f.write('void f(void)\n')
155+
f.write('{ // cppcheck-suppress id1\n')
156+
f.write(' // cppcheck-suppress id2\n')
157+
f.write(' x = 0;\n')
158+
f.write('}\n')
159+
160+
exitcode, _, stderr = cppcheck(['--dump', '--inline-suppr', test_file])
161+
assert exitcode == 0, stderr
162+
163+
dumpfile = test_file + '.dump'
164+
with open(dumpfile, 'rt') as f:
165+
dump = f.read()
166+
assert 'lineNumber="2" thisAndNextLine="true" inline="true"' in dump
167+
assert 'lineNumber="4" inline="true"' in dump

0 commit comments

Comments
 (0)