Skip to content

Commit 2d5404d

Browse files
fallbergtbowmo
authored andcommitted
CppCheck cleanup (#975)
* Add support for inline cppcheck suppressions * Clean out all known cppcheck issues * Terminate toll-gate on found cppcheck issues
1 parent e2ac85a commit 2d5404d

File tree

23 files changed

+86
-50
lines changed

23 files changed

+86
-50
lines changed

.ci/static_analysis.groovy

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def cppCheck(config) {
55
sh """#!/bin/bash +x
66
cd ${config.repository_root}
77
echo "Doing cppcheck for AVR..."
8-
find . -type f \\( -iname \\*.c -o -iname \\*.cpp -o -iname \\*.ino \\) | cppcheck -j 4 --file-list=- --enable=style,information --platform=.mystools/cppcheck/config/avr.xml --suppressions-list=.mystools/cppcheck/config/suppressions.cfg --includes-file=.mystools/cppcheck/config/includes.cfg --language=c++ --xml --xml-version=2 2> cppcheck-avr.xml
8+
find . -type f \\( -iname \\*.c -o -iname \\*.cpp -o -iname \\*.ino \\) | cppcheck -j 4 --force --file-list=- --enable=style,information --platform=.mystools/cppcheck/config/avr.xml --suppressions-list=.mystools/cppcheck/config/suppressions.cfg --includes-file=.mystools/cppcheck/config/includes.cfg --language=c++ --inline-suppr --xml --xml-version=2 2> cppcheck-avr.xml
99
cppcheck-htmlreport --file="cppcheck-avr.xml" --title="cppcheck-avr" --report-dir=cppcheck-avr_cppcheck_reports --source-dir=."""
1010

1111
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: true,
@@ -29,9 +29,8 @@ def cppCheck(config) {
2929
"grep -q \"<td>0</td><td>total</td>\" cppcheck-avr_cppcheck_reports/index.html || exit_code=\$?\n"+
3030
"exit \$((exit_code == 0 ? 0 : 1))")
3131
if (ret == 1) {
32-
config.pr.setBuildStatus(config, 'SUCCESS', 'Toll gate (Code analysis - Cppcheck)', 'Issues found (but are not considered critical)', '${BUILD_URL}CppCheck_AVR/index.html')
33-
//currentBuild.result = 'UNSTABLE'
34-
//error 'Terminating due to Cppcheck error'
32+
config.pr.setBuildStatus(config, 'ERROR', 'Toll gate (Code analysis - Cppcheck)', 'Issues found', '${BUILD_URL}CppCheck_AVR/index.html')
33+
error 'Terminating due to Cppcheck error'
3534
} else {
3635
config.pr.setBuildStatus(config, 'SUCCESS', 'Toll gate (Code analysis - Cppcheck)', 'Pass', '')
3736
}

.clang_complete

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino
2-
-IC:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include
31
-Idrivers\Linux
42
-Idrivers\ATSHA204
53
-Icore
6-
-DMY_SIGNING_ATSHA204
7-
-DMY_SIGNING_SOFT
8-
-DARDUINO_ARCH_AVR
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
toomanyconfigs
2-
missingInclude
3-
missingIncludeSystem
41
ConfigurationNotChecked
52
unmatchedSuppression
3+
// This suppression is because the problem is in an in-lined macro so in-line-suppressions does not appear to take effect
4+
unreadVariable:*/MyHwNRF5.cpp

.mystools/cppcheck/options.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ OPTIONS="--quiet \
99
--library=${LIBRARY:-avr} \
1010
--platform="${TOOLCONFIG}"/${PLATFORM:-avr.xml} \
1111
--includes-file="${TOOLCONFIG}"/includes.cfg \
12+
--inline-suppr \
1213
--suppressions-list="${TOOLCONFIG}"/suppressions.cfg"
1314

1415
echo $OPTIONS

core/MyGatewayTransportEthernet.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ MyMessage _ethernetMsg;
4949
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
5050

5151
typedef struct {
52+
// Suppress the warning about unused members in this struct because it is used through a complex
53+
// set of preprocessor directives
54+
// cppcheck-suppress unusedStructMember
5255
char string[MY_GATEWAY_MAX_RECEIVE_LENGTH];
56+
// cppcheck-suppress unusedStructMember
5357
uint8_t idx;
5458
} inputBuffer;
5559

core/MyLeds.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ void ledsProcess()
5858
}
5959
prevTime = hwMillis();
6060

61+
#if defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
6162
uint8_t state;
63+
#endif
6264

6365
// For an On/Off ratio of 4, the pattern repeated will be [on, on, on, off]
6466
// until the counter becomes 0.

core/MyOTAFirmwareUpdate.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ bool firmwareOTAUpdateProcess(void)
128128
MY_SERIALDEVICE.print(prbuf);
129129
}
130130
OTA_DEBUG(PSTR("\n"));
131-
8
132131
}
133132
#endif
134133
_firmwareBlock--;

core/MyProtocolMySensors.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ bool protocolParse(MyMessage &message, char *inputString)
5959
break;
6060
case 5: // Variable value
6161
if (command == C_STREAM) {
62-
blen = 0;
6362
while (*str) {
6463
uint8_t val;
6564
val = protocolH2i(*str++) << 4;
@@ -125,8 +124,6 @@ bool protocolMQTTParse(MyMessage &message, char* topic, uint8_t* payload, unsign
125124
{
126125
char *str, *p;
127126
uint8_t i = 0;
128-
uint8_t bvalue[MAX_PAYLOAD];
129-
uint8_t blen = 0;
130127
uint8_t command = 0;
131128
if (topic != strstr(topic, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX)) {
132129
// Prefix doesn't match incoming topic
@@ -175,9 +172,10 @@ bool protocolMQTTParse(MyMessage &message, char* topic, uint8_t* payload, unsign
175172

176173
// Add payload
177174
if (command == C_STREAM) {
178-
blen = 0;
179-
uint8_t val;
175+
uint8_t bvalue[MAX_PAYLOAD];
176+
uint8_t blen = 0;
180177
while (*payload) {
178+
uint8_t val;
181179
val = protocolH2i(*payload++) << 4;
182180
val += protocolH2i(*payload++);
183181
bvalue[blen] = val;

core/MySigning.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ void signerInit(void)
111111
#endif
112112
#if (defined (MY_ENCRYPTION_FEATURE) || defined (MY_SIGNING_FEATURE)) &&\
113113
!defined (MY_SIGNING_SIMPLE_PASSWD)
114+
// Suppress this warning since it is only fixed on Linux builds and this keeps the code more tidy
115+
// cppcheck-suppress knownConditionTrueFalse
114116
if (!signerInternalValidatePersonalization()) {
115117
SIGN_DEBUG(PSTR("!SGN:PER:TAMPERED\n"));
116118
#if defined(MY_SIGNING_FEATURE)

core/MySigningAtsha204Soft.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ bool signerAtsha204SoftInit(void)
103103
_signing_node_serial_info[8] = getNodeId();
104104
}
105105
#else
106-
if (init_ok) {
107-
hwReadConfigBlock((void*)_signing_hmac_key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
108-
hwReadConfigBlock((void*)_signing_node_serial_info, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
109-
}
106+
hwReadConfigBlock((void*)_signing_hmac_key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
107+
hwReadConfigBlock((void*)_signing_node_serial_info, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
110108
#endif
111109
if (!memcmp(_signing_node_serial_info, reset_serial, 9)) {
112110
unique_id_t uniqueID;

0 commit comments

Comments
 (0)