Skip to content

Commit d1519ba

Browse files
authored
Merge pull request SonarOpenCommunity#1687 from ivangalkin/cppcheck187
Support for cppcheck 1.87
2 parents 0a618ba + 321dda7 commit d1519ba

File tree

3 files changed

+152
-29
lines changed

3 files changed

+152
-29
lines changed

cxx-sensors/src/main/resources/cppcheck.xml

Lines changed: 149 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ Pointer to local array variable returned.
138138
</rule>
139139
<rule>
140140
<key>returnReference</key>
141-
<name>Reference to auto variable returned</name>
141+
<name>Reference to local variable returned</name>
142142
<description>
143-
<![CDATA[
144-
<p>
145-
Reference to auto variable returned.
143+
<![CDATA[
144+
<p>
145+
Reference to local variable returned.
146146
</p>
147147
<h2>References</h2>
148148
<p><a href="https://cwe.mitre.org/data/definitions/562.html" target="_blank">CWE-562: Return of Stack Variable Address</a></p>
@@ -2223,7 +2223,7 @@ Redundant assignment to itself.
22232223
<description>
22242224
<![CDATA[
22252225
<p>
2226-
Variable 'var' is modified insert assert statement. Assert statements
2226+
Variable 'var' is modified inside assert statement. Assert statements
22272227
are removed from release builds so the code inside assert statement is
22282228
not executed. If the code is needed also in release builds, this is a
22292229
bug.
@@ -2503,12 +2503,12 @@ be removed.
25032503
</rule>
25042504
<rule>
25052505
<key>unsignedLessThanZero</key>
2506-
<name>Checking if unsigned variable is less than zero</name>
2506+
<name>Checking if unsigned expression is less than zero</name>
25072507
<description>
25082508
<![CDATA[
25092509
<p>
2510-
The unsigned variable 'varname' will never be negative so it is either
2511-
pointless or an error to check if it is.
2510+
The unsigned expression 'varname' will never be negative so it is
2511+
either pointless or an error to check if it is.
25122512
</p>
25132513
<h2>References</h2>
25142514
<p><a href="https://cwe.mitre.org/data/definitions/570.html" target="_blank">CWE-570: Expression is Always False</a></p>
@@ -2523,12 +2523,12 @@ pointless or an error to check if it is.
25232523
</rule>
25242524
<rule>
25252525
<key>unsignedPositive</key>
2526-
<name>An unsigned variable can't be negative so it is unnecessary to test it</name>
2526+
<name>An unsigned expression can't be negative so it is unnecessary to test it</name>
25272527
<description>
25282528
<![CDATA[
25292529
<p>
2530-
Unsigned variable 'varname' can't be negative so it is unnecessary to
2531-
test it.
2530+
Unsigned expression 'varname' can't be negative so it is unnecessary
2531+
to test it.
25322532
</p>
25332533
<h2>References</h2>
25342534
<p><a href="https://cwe.mitre.org/data/definitions/570.html" target="_blank">CWE-570: Expression is Always False</a></p>
@@ -2602,7 +2602,7 @@ Iterators of different containers are used together.
26022602
</rule>
26032603
<rule>
26042604
<key>eraseDereference</key>
2605-
<name>Dereferenced iterator an already erased iterator</name>
2605+
<name>Invalid iterator used</name>
26062606
<description>
26072607
<![CDATA[
26082608
<p>
@@ -3823,7 +3823,7 @@ Redundant condition: If <code>x > 11</code> the condition <code>x > 10</code> is
38233823
</rule>
38243824
<rule>
38253825
<key>virtualDestructor</key>
3826-
<name>Base classes should have virtual destructors</name>
3826+
<name>Base classes should have virtual destructor</name>
38273827
<description>
38283828
<![CDATA[
38293829
<p>
@@ -5197,7 +5197,7 @@ calculations, the behaviour is undefined. Arithmetic operations on
51975197
</rule>
51985198
<rule>
51995199
<key>commaSeparatedReturn</key>
5200-
<name>Usage of comma in return statements</name>
5200+
<name>Usage of comma in return statement</name>
52015201
<description>
52025202
<![CDATA[
52035203
<p>
@@ -9370,7 +9370,6 @@ Non-local variable 'x' will use object.
93709370
<h2>References</h2>
93719371
<p><a href="https://cwe.mitre.org/data/definitions/562.html" target="_blank">CWE-562: Return of Stack Variable Address</a></p>
93729372
]]>
9373-
<![CDATA[]]>
93749373
</description>
93759374
<tag>cwe</tag>
93769375
<tag>bug</tag>
@@ -9393,7 +9392,6 @@ examine this code carefully to determine if it is correct.
93939392
<h2>References</h2>
93949393
<p><a href="https://cwe.mitre.org/data/definitions/398.html" target="_blank">CWE-398: 7PK - Code Quality</a></p>
93959394
]]>
9396-
<![CDATA[]]>
93979395
</description>
93989396
<tag>cwe</tag>
93999397
<internalKey>duplicateAssignExpression</internalKey>
@@ -9414,7 +9412,6 @@ required.
94149412
<h2>References</h2>
94159413
<p><a href="https://cwe.mitre.org/data/definitions/628.html" target="_blank">CWE-628: Function Call with Incorrectly Specified Arguments</a></p>
94169414
]]>
9417-
<![CDATA[]]>
94189415
</description>
94199416
<tag>cwe</tag>
94209417
<tag>bug</tag>
@@ -9435,7 +9432,6 @@ Using object that is out of scope.
94359432
<h2>References</h2>
94369433
<p><a href="https://cwe.mitre.org/data/definitions/562.html" target="_blank">CWE-562: Return of Stack Variable Address</a></p>
94379434
]]>
9438-
<![CDATA[]]>
94399435
</description>
94409436
<tag>cwe</tag>
94419437
<tag>bug</tag>
@@ -9457,7 +9453,6 @@ Same iterator is used with different containers 'container1' and
94579453
<h2>References</h2>
94589454
<p><a href="https://cwe.mitre.org/data/definitions/664.html" target="_blank">CWE-664: Improper Control of a Resource Through its Lifetime</a></p>
94599455
]]>
9460-
<![CDATA[]]>
94619456
</description>
94629457
<tag>cwe</tag>
94639458
<tag>bug</tag>
@@ -9479,7 +9474,6 @@ different scopes.
94799474
<h2>References</h2>
94809475
<p><a href="https://cwe.mitre.org/data/definitions/664.html" target="_blank">CWE-664: Improper Control of a Resource Through its Lifetime</a></p>
94819476
]]>
9482-
<![CDATA[]]>
94839477
</description>
94849478
<tag>cwe</tag>
94859479
<tag>bug</tag>
@@ -9500,7 +9494,6 @@ Comparison of iterators from containers 'container1' and 'container2'.
95009494
<h2>References</h2>
95019495
<p><a href="https://cwe.mitre.org/data/definitions/664.html" target="_blank">CWE-664: Improper Control of a Resource Through its Lifetime</a></p>
95029496
]]>
9503-
<![CDATA[]]>
95049497
</description>
95059498
<tag>cwe</tag>
95069499
<tag>bug</tag>
@@ -9522,7 +9515,6 @@ in different scopes.
95229515
<h2>References</h2>
95239516
<p><a href="https://cwe.mitre.org/data/definitions/664.html" target="_blank">CWE-664: Improper Control of a Resource Through its Lifetime</a></p>
95249517
]]>
9525-
<![CDATA[]]>
95269518
</description>
95279519
<tag>cwe</tag>
95289520
<tag>bug</tag>
@@ -9543,7 +9535,6 @@ Returning object that will be invalid when returning.
95439535
<h2>References</h2>
95449536
<p><a href="https://cwe.mitre.org/data/definitions/562.html" target="_blank">CWE-562: Return of Stack Variable Address</a></p>
95459537
]]>
9546-
<![CDATA[]]>
95479538
</description>
95489539
<tag>cwe</tag>
95499540
<tag>bug</tag>
@@ -9560,7 +9551,6 @@ Returning object that will be invalid when returning.
95609551
<![CDATA[
95619552
Non-boolean value returned from function returning bool
95629553
]]>
9563-
<![CDATA[]]>
95649554
</description>
95659555
<internalKey>returnNonBoolInBooleanFunction</internalKey>
95669556
<severity>MINOR</severity>
@@ -9579,7 +9569,6 @@ Local variable shadows outer function
95799569
<h2>References</h2>
95809570
<p><a href="https://cwe.mitre.org/data/definitions/398.html" target="_blank">CWE-398: 7PK - Code Quality</a></p>
95819571
]]>
9582-
<![CDATA[]]>
95839572
</description>
95849573
<tag>cwe</tag>
95859574
<internalKey>shadowFunction</internalKey>
@@ -9599,7 +9588,6 @@ Local variable shadows outer variable
95999588
<h2>References</h2>
96009589
<p><a href="https://cwe.mitre.org/data/definitions/398.html" target="_blank">CWE-398: 7PK - Code Quality</a></p>
96019590
]]>
9602-
<![CDATA[]]>
96039591
</description>
96049592
<tag>cwe</tag>
96059593
<internalKey>shadowVar</internalKey>
@@ -9608,4 +9596,139 @@ Local variable shadows outer variable
96089596
<remediationFunction>LINEAR</remediationFunction>
96099597
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
96109598
</rule>
9599+
<rule>
9600+
<key>constArgument</key>
9601+
<name>Const argument</name>
9602+
<description>
9603+
<![CDATA[
9604+
<p>
9605+
Argument 'x' to function f is always 0
9606+
</p>
9607+
<h2>References</h2>
9608+
<p><a href="https://cwe.mitre.org/data/definitions/570.html" target="_blank">CWE-570: Expression is Always False</a></p>
9609+
]]>
9610+
</description>
9611+
<tag>cwe</tag>
9612+
<internalKey>constArgument</internalKey>
9613+
<severity>MINOR</severity>
9614+
<type>CODE_SMELL</type>
9615+
<remediationFunction>LINEAR</remediationFunction>
9616+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
9617+
</rule>
9618+
<rule>
9619+
<key>danglingReference</key>
9620+
<name>Dangling reference</name>
9621+
<description>
9622+
<![CDATA[
9623+
<p>
9624+
Non-local reference variable 'x' to local variable 'y'
9625+
</p>
9626+
<h2>References</h2>
9627+
<p><a href="https://cwe.mitre.org/data/definitions/562.html" target="_blank">CWE-562: Return of Stack Variable Address</a></p>
9628+
]]>
9629+
</description>
9630+
<tag>cwe</tag>
9631+
<tag>bug</tag>
9632+
<internalKey>danglingReference</internalKey>
9633+
<severity>MAJOR</severity>
9634+
<type>BUG</type>
9635+
<remediationFunction>LINEAR</remediationFunction>
9636+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
9637+
</rule>
9638+
<rule>
9639+
<key>duplicateCondition</key>
9640+
<name>Duplicate condition</name>
9641+
<description>
9642+
<![CDATA[
9643+
<p>
9644+
The if condition is the same as the previous if condition
9645+
</p>
9646+
<h2>References</h2>
9647+
<p><a href="https://cwe.mitre.org/data/definitions/398.html" target="_blank">CWE-398: 7PK - Code Quality</a></p>
9648+
]]>
9649+
</description>
9650+
<tag>cwe</tag>
9651+
<internalKey>duplicateCondition</internalKey>
9652+
<severity>MINOR</severity>
9653+
<type>CODE_SMELL</type>
9654+
<remediationFunction>LINEAR</remediationFunction>
9655+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
9656+
</rule>
9657+
<rule>
9658+
<key>invalidScanfFormatWidth_smaller</key>
9659+
<name>Wrong width for scanf parameter (too small)</name>
9660+
<description>
9661+
<![CDATA[
9662+
Width 'w0' given in format string is smaller than destination buffer '[w1]'.
9663+
]]>
9664+
</description>
9665+
<tag>bug</tag>
9666+
<internalKey>invalidScanfFormatWidth_smaller</internalKey>
9667+
<severity>MINOR</severity>
9668+
<type>BUG</type>
9669+
<remediationFunction>LINEAR</remediationFunction>
9670+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
9671+
</rule>
9672+
<rule>
9673+
<key>iterators2</key>
9674+
<name>Same iterator is used with different containers</name>
9675+
<description>
9676+
<![CDATA[
9677+
<p>
9678+
Same iterator is used with different containers 'container0' and
9679+
'container1'.
9680+
</p>
9681+
<h2>References</h2>
9682+
<p><a href="https://cwe.mitre.org/data/definitions/664.html" target="_blank">CWE-664: Improper Control of a Resource Through its Lifetime</a></p>
9683+
]]>
9684+
</description>
9685+
<tag>cwe</tag>
9686+
<tag>bug</tag>
9687+
<internalKey>iterators2</internalKey>
9688+
<severity>MAJOR</severity>
9689+
<type>BUG</type>
9690+
<remediationFunction>LINEAR</remediationFunction>
9691+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
9692+
</rule>
9693+
<rule>
9694+
<key>nullPointerArithmeticRedundantCheck</key>
9695+
<name>Redundant condition or NULL pointer arithmetic</name>
9696+
<description>
9697+
<![CDATA[
9698+
<p>
9699+
Either the condition is redundant or there is pointer arithmetic with
9700+
NULL pointer.
9701+
</p>
9702+
<h2>References</h2>
9703+
<p><a href="https://cwe.mitre.org/data/definitions/682.html" target="_blank">CWE-682: Incorrect Calculation</a></p>
9704+
]]>
9705+
</description>
9706+
<tag>cwe</tag>
9707+
<tag>bug</tag>
9708+
<internalKey>nullPointerArithmeticRedundantCheck</internalKey>
9709+
<severity>MINOR</severity>
9710+
<type>BUG</type>
9711+
<remediationFunction>LINEAR</remediationFunction>
9712+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
9713+
</rule>
9714+
<rule>
9715+
<key>wxBitmap::SetDepthCalled</key>
9716+
<name>This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time</name>
9717+
<description>
9718+
<![CDATA[
9719+
<p>
9720+
This function is deprecated since version 3.1.2, dimensions and depth
9721+
can only be set at construction time.
9722+
</p>
9723+
<h2>References</h2>
9724+
<p><a href="https://cwe.mitre.org/data/definitions/477.html" target="_blank">CWE-477: Use of Obsolete Function</a></p>
9725+
]]>
9726+
</description>
9727+
<tag>cwe</tag>
9728+
<internalKey>wxBitmap::SetDepthCalled</internalKey>
9729+
<severity>MINOR</severity>
9730+
<type>CODE_SMELL</type>
9731+
<remediationFunction>LINEAR</remediationFunction>
9732+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
9733+
</rule>
96119734
</rules>

cxx-sensors/src/test/java/org/sonar/cxx/sensors/cppcheck/CxxCppCheckRuleRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void createRulesTest() {
4141
def.define(context);
4242

4343
RulesDefinition.Repository repo = context.repository(CxxCppCheckRuleRepository.getRepositoryKey(language));
44-
assertEquals(503, repo.rules().size());
44+
assertEquals(510, repo.rules().size());
4545
}
4646

4747
}

cxx-sensors/src/tools/generate_cppcheck_resources.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ done
1515

1616
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1717

18-
wget https://cwe.mitre.org/data/xml/cwec_v3.1.xml.zip --output-document=cwec_v3.1.xml.zip && unzip -j -o cwec_v3.1.xml.zip
18+
wget https://cwe.mitre.org/data/xml/cwec_v3.2.xml.zip --output-document=cwec_v3.2.xml.zip && unzip -j -o cwec_v3.2.xml.zip
1919

2020
cppcheck ${CPPCHECK_LIBRARY_ARGS} --errorlist --xml-version=2 > cppcheck-errorlist.xml
21-
cppcheck ${CPPCHECK_LIBRARY_ARGS} --errorlist --xml-version=2 | python cppcheck_createrules.py rules cwec_v3.1.xml > cppcheck.xml
21+
cppcheck ${CPPCHECK_LIBRARY_ARGS} --errorlist --xml-version=2 | python cppcheck_createrules.py rules cwec_v3.2.xml > cppcheck.xml
2222
python utils_createrules.py comparerules $SCRIPT_DIR/../main/resources/cppcheck.xml cppcheck.xml > cppcheck-comparison.md

0 commit comments

Comments
 (0)