Skip to content

Commit f53968e

Browse files
authored
Merge pull request #2220 from guwirth/cppcheck-2.5
Cppcheck 2.5 rule support
2 parents fe42914 + 8e484f3 commit f53968e

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5125,7 +5125,7 @@ Dangerous usage of c_str(). The string is destroyed after the c_str() call so th
51255125
<remediationFunction>LINEAR</remediationFunction>
51265126
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
51275127
</rule>
5128-
<!-- ########### New in Cppcheck 1.69 Dev ########### -->
5128+
<!-- ########### New in Cppcheck 1.69 ########### -->
51295129
<rule>
51305130
<key>duplicateExpressionTernary</key>
51315131
<name>Same expression in both branches of ternary operator</name>
@@ -5263,7 +5263,7 @@ appropriate C library function.
52635263
<remediationFunction>LINEAR</remediationFunction>
52645264
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
52655265
</rule>
5266-
<!-- ########### New in Cppcheck 1.70 release ########### -->
5266+
<!-- ########### New in Cppcheck 1.70 ########### -->
52675267
<rule>
52685268
<key>negativeArraySize</key>
52695269
<name>Declaration of array with negative size is undefined behaviour</name>
@@ -8839,6 +8839,42 @@ be used in code that is removed by the preprocessor. Should this be a
88398839
<type>BUG</type>
88408840
<remediationFunction>LINEAR</remediationFunction>
88418841
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
8842+
</rule>
8843+
<!-- ########### New in Cppcheck 2.50 ########### -->
8844+
<rule>
8845+
<key>assignmentInCondition</key>
8846+
<name>Suspicious assignment in condition. Condition 'x=y' is always true</name>
8847+
<description><![CDATA[
8848+
<p>
8849+
Suspicious assignment in condition. Condition 'x=y' is always true.
8850+
</p>
8851+
<h2>References</h2>
8852+
<p><a href="https://cwe.mitre.org/data/definitions/571.html" target="_blank">CWE-571: Expression is Always True</a></p>
8853+
]]></description>
8854+
<tag>cwe</tag>
8855+
<severity>MINOR</severity>
8856+
<type>CODE_SMELL</type>
8857+
<remediationFunction>LINEAR</remediationFunction>
8858+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
8859+
</rule>
8860+
<rule>
8861+
<key>rethrowNoCurrentException</key>
8862+
<name>Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow</name>
8863+
<description><![CDATA[
8864+
<p>
8865+
Rethrowing current exception with 'throw;', it seems there is no
8866+
current exception to rethrow. If there is no current exception this
8867+
calls std::terminate(). More:
8868+
https://isocpp.org/wiki/faq/exceptions#throw-without-an-object
8869+
</p>
8870+
<h2>References</h2>
8871+
<p><a href="https://cwe.mitre.org/data/definitions/480.html" target="_blank">CWE-480: Use of Incorrect Operator</a></p>
8872+
]]></description>
8873+
<tag>cwe</tag>
8874+
<severity>MAJOR</severity>
8875+
<type>BUG</type>
8876+
<remediationFunction>LINEAR</remediationFunction>
8877+
<remediationFunctionGapMultiplier>5min</remediationFunctionGapMultiplier>
88428878
</rule>
88438879
<!-- ########### Misra Rules ########### -->
88448880
<rule>

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
@@ -37,7 +37,7 @@ public void createRulesTest() {
3737
def.define(context);
3838

3939
RulesDefinition.Repository repo = context.repository(CxxCppCheckRuleRepository.KEY);
40-
assertEquals(657, repo.rules().size());
40+
assertEquals(659, repo.rules().size());
4141
}
4242

4343
}
19.6 KB
Binary file not shown.

cxx-sensors/src/tools/generate_cppcheck_resources.cmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ SET SCRIPT_DIR=%~dp0
55
SET CPPCHECK_DIR=C:\Program Files\Cppcheck\
66
SET PYTHON_DIR=
77

8-
SET CPPCHECK_LIBRARY_ARGS=--library=avr.cfg --library=boost.cfg --library=bsd.cfg --library=cairo.cfg --library=cppunit.cfg --library=embedded_sql.cfg --library=gnu.cfg --library=googletest.cfg --library=gtk.cfg --library=kde.cfg --library=libcerror.cfg --library=libcurl.cfg --library=libsigc++.cfg --library=lua.cfg --library=mfc.cfg --library=microsoft_atl.cfg --library=microsoft_sal.cfg --library=microsoft_unittest.cfg --library=motif.cfg --library=nspr.cfg --library=opencv2.cfg --library=opengl.cfg --library=openmp.cfg --library=openssl.cfg --library=posix.cfg --library=python.cfg --library=qt.cfg --library=ruby.cfg --library=sdl.cfg --library=sfml.cfg --library=sqlite3.cfg --library=std.cfg --library=tinyxml2.cfg --library=windows.cfg --library=wxwidgets.cfg --library=zlib.cfg
8+
SET CPPCHECK_LIBRARY_ARGS=--library=avr.cfg --library=bento4.cfg --library=boost.cfg --library=bsd.cfg --library=cairo.cfg --library=cppunit.cfg --library=dpdk.cfg --library=embedded_sql.cfg --library=gnu.cfg --library=googletest.cfg --library=gtk.cfg --library=kde.cfg --library=libcerror.cfg --library=libcurl.cfg --library=libsigc++.cfg --library=lua.cfg --library=mfc.cfg--library=microsoft_atl.cfg --library=microsoft_sal.cfg --library=microsoft_unittest.cfg --library=motif.cfg --library=nspr.cfg --library=opencv2.cfg --library=opengl.cfg --library=openmp.cfg --library=openssl.cfg --library=posix.cfg --library=python.cfg --library=qt.cfg --library=ruby.cfg --library=sdl.cfg --library=sfml.cfg --library=sqlite3.cfg --library=std.cfg --library=tinyxml2.cfg --library=vcl.cfg --library=windows.cfg --library=wxwidgets.cfg --library=zlib.cfg
99

10-
rem download cwec_latest.xml.zip und unzip cwec_vx.y.xml
10+
rem download cwec_latest.xml.zip and extract it to unzip cwec_vx.y.xml
1111
rem wget https://cwe.mitre.org/data/xml/cwec_latest.xml.zip --output-document=cwec_latest.xml.zip && unzip -j -o cwec_latest.xml.zip
1212

1313
"%PYTHON_DIR%python.exe" -V
@@ -16,7 +16,7 @@ ECHO create Cppcheck errorlist cppcheck-errorlist.xml...
1616
"%CPPCHECK_DIR%cppcheck.exe" %CPPCHECK_LIBRARY_ARGS% --errorlist --xml-version=2 > cppcheck-errorlist.xml
1717

1818
ECHO create SonarQube rules file cppcheck.xml...
19-
"%CPPCHECK_DIR%cppcheck.exe" %CPPCHECK_LIBRARY_ARGS% --errorlist --xml-version=2 | "%PYTHON_DIR%python.exe" cppcheck_createrules.py rules cwec_v4.4.xml > cppcheck.xml
19+
"%CPPCHECK_DIR%cppcheck.exe" %CPPCHECK_LIBRARY_ARGS% --errorlist --xml-version=2 | "%PYTHON_DIR%python.exe" cppcheck_createrules.py rules cwec_v4.5.xml > cppcheck.xml
2020

2121
ECHO create cppcheck-comparison.md...
2222
"%PYTHON_DIR%python.exe" utils_createrules.py comparerules "%SCRIPT_DIR%\..\main\resources\cppcheck.xml" .\cppcheck.xml > cppcheck-comparison.md

0 commit comments

Comments
 (0)