CppCheck cleanup (#975)
* Add support for inline cppcheck suppressions * Clean out all known cppcheck issues * Terminate toll-gate on found cppcheck issues
This commit is contained in:
committed by
Thomas Mørch
parent
e2ac85afbb
commit
2d5404de97
+3
-3
@@ -407,11 +407,11 @@ byte AES::cbc_encrypt (byte * plain, byte * cipher, int n_block)
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
byte AES::decrypt (byte plain [N_BLOCK], byte cipher [N_BLOCK])
|
||||
byte AES::decrypt (byte cipher [N_BLOCK], byte plain [N_BLOCK])
|
||||
{
|
||||
if (round) {
|
||||
byte s1 [N_BLOCK] ;
|
||||
copy_and_key (s1, plain, (byte*) (key_sched + round * N_BLOCK)) ;
|
||||
copy_and_key (s1, cipher, (byte*) (key_sched + round * N_BLOCK)) ;
|
||||
inv_shift_sub_rows (s1) ;
|
||||
|
||||
for (byte r = round ; --r ; ) {
|
||||
@@ -419,7 +419,7 @@ byte AES::decrypt (byte plain [N_BLOCK], byte cipher [N_BLOCK])
|
||||
copy_and_key (s2, s1, (byte*) (key_sched + r * N_BLOCK)) ;
|
||||
inv_mix_sub_columns (s1, s2) ;
|
||||
}
|
||||
copy_and_key (cipher, s1, (byte*) (key_sched)) ;
|
||||
copy_and_key (plain, s1, (byte*) (key_sched)) ;
|
||||
} else {
|
||||
return AES_FAILURE ;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ const uint8_t sha256InitState[] PROGMEM = {
|
||||
0x19,0xcd,0xe0,0x5b // H7
|
||||
};
|
||||
|
||||
// Suppress warning about uninitialized variables because initializing them in an init function
|
||||
// allows the compiler to optimize away the variables in case the class is only instantiated but
|
||||
// never used.
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
Sha256Class::Sha256Class()
|
||||
{
|
||||
/*
|
||||
@@ -165,6 +169,10 @@ uint8_t* Sha256Class::result(void)
|
||||
#define HMAC_IPAD 0x36
|
||||
#define HMAC_OPAD 0x5c
|
||||
|
||||
// Suppress warning about uninitialized variables because initializing them in an init function
|
||||
// allows the compiler to optimize away the variables in case the class is only instantiated but
|
||||
// never used.
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
HmacClass::HmacClass()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ class PinIO
|
||||
{
|
||||
public:
|
||||
/** Create a PinIO object with no assigned pin. */
|
||||
// Suppress warning about uninitialized variables because initializing them in an init function
|
||||
// allows the compiler to optimize away the variables in case the class is only instantiated but
|
||||
// never used.
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PinIO() : bit_(0), mask_(0XFF) {}
|
||||
/** Constructor
|
||||
* @param[in] pin Pin assigned to this object.
|
||||
@@ -186,4 +190,4 @@ private:
|
||||
volatile uint8_t* portReg_;
|
||||
};
|
||||
#endif // PinIO_h
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
@@ -179,7 +179,6 @@ void dumpAll(void)
|
||||
//------------------------------------------------------------------------------
|
||||
void fillNvRam(void)
|
||||
{
|
||||
uint8_t buf[8];
|
||||
PgmPrint("Enter HEX value for all NV RAM locations (00-FF): ");
|
||||
uint16_t v;
|
||||
if (!hexRead(&v)) {
|
||||
@@ -363,4 +362,4 @@ void loop(void)
|
||||
} else {
|
||||
PgmPrintln("Invalid option");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,13 +131,14 @@ void AltSoftSerial::writeByte(uint8_t b)
|
||||
|
||||
ISR(COMPARE_A_INTERRUPT)
|
||||
{
|
||||
uint8_t state, byte, bit, head, tail;
|
||||
uint8_t state, byte, head, tail;
|
||||
uint16_t target;
|
||||
|
||||
state = tx_state;
|
||||
byte = tx_byte;
|
||||
target = GET_COMPARE_A();
|
||||
while (state < 9) {
|
||||
uint8_t bit;
|
||||
target += ticks_per_bit;
|
||||
bit = byte & 1;
|
||||
byte >>= 1;
|
||||
@@ -195,9 +196,8 @@ void AltSoftSerial::flushOutput(void)
|
||||
|
||||
ISR(CAPTURE_INTERRUPT)
|
||||
{
|
||||
uint8_t state, bit, head;
|
||||
uint16_t capture, target;
|
||||
int16_t offset;
|
||||
uint8_t state, bit;
|
||||
uint16_t capture;
|
||||
|
||||
capture = GET_INPUT_CAPTURE();
|
||||
bit = rx_bit;
|
||||
@@ -217,8 +217,10 @@ ISR(CAPTURE_INTERRUPT)
|
||||
rx_state = 1;
|
||||
}
|
||||
} else {
|
||||
uint16_t target;
|
||||
target = rx_target;
|
||||
while (1) {
|
||||
int16_t offset;
|
||||
offset = capture - target;
|
||||
if (offset < 0) {
|
||||
break;
|
||||
@@ -227,6 +229,7 @@ ISR(CAPTURE_INTERRUPT)
|
||||
target += ticks_per_bit;
|
||||
state++;
|
||||
if (state >= 9) {
|
||||
uint8_t head;
|
||||
DISABLE_INT_COMPARE_B();
|
||||
head = rx_buffer_head + 1;
|
||||
if (head >= RX_BUFFER_SIZE) {
|
||||
|
||||
@@ -113,11 +113,11 @@ unsigned int bcm2835_version(void)
|
||||
*/
|
||||
uint32_t bcm2835_peri_read(volatile uint32_t* paddr)
|
||||
{
|
||||
uint32_t ret;
|
||||
if (debug) {
|
||||
printf("bcm2835_peri_read paddr %08X\n", (unsigned) paddr);
|
||||
return 0;
|
||||
} else {
|
||||
uint32_t ret;
|
||||
__sync_synchronize();
|
||||
ret = *paddr;
|
||||
__sync_synchronize();
|
||||
@@ -438,7 +438,7 @@ void bcm2835_delayMicroseconds(uint64_t micros)
|
||||
|
||||
if (debug) {
|
||||
/* Cant access sytem timers in debug mode */
|
||||
printf("bcm2835_delayMicroseconds %lld\n", micros);
|
||||
printf("bcm2835_delayMicroseconds %" PRIu64 "\n", micros);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
// private method to read stream with timeout
|
||||
int Stream::timedRead()
|
||||
{
|
||||
int c;
|
||||
_startMillis = millis();
|
||||
do {
|
||||
int c;
|
||||
c = read();
|
||||
if(c >= 0) {
|
||||
return c;
|
||||
@@ -45,9 +45,9 @@ int Stream::timedRead()
|
||||
// private method to peek stream with timeout
|
||||
int Stream::timedPeek()
|
||||
{
|
||||
int c;
|
||||
_startMillis = millis();
|
||||
do {
|
||||
int c;
|
||||
c = peek();
|
||||
if(c >= 0) {
|
||||
return c;
|
||||
@@ -61,8 +61,8 @@ int Stream::timedPeek()
|
||||
// discards non-numeric characters
|
||||
int Stream::peekNextDigit()
|
||||
{
|
||||
int c;
|
||||
while(1) {
|
||||
int c;
|
||||
c = timedPeek();
|
||||
if(c < 0) {
|
||||
return c; // timeout
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include "PubSubClient.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
// Suppress uninitialized member variable in all constructors because some memory can be saved with
|
||||
// on-demand initialization of these members
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PubSubClient::PubSubClient()
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -15,6 +18,7 @@ PubSubClient::PubSubClient()
|
||||
setCallback(NULL);
|
||||
}
|
||||
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PubSubClient::PubSubClient(Client& client)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -22,6 +26,7 @@ PubSubClient::PubSubClient(Client& client)
|
||||
this->stream = NULL;
|
||||
}
|
||||
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -29,6 +34,7 @@ PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client)
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client, Stream& stream)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -36,6 +42,8 @@ PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client, Stream
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
// cppcheck-suppress passedByValue
|
||||
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -44,6 +52,8 @@ PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATUR
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
// cppcheck-suppress passedByValue
|
||||
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client,
|
||||
Stream& stream)
|
||||
{
|
||||
@@ -54,6 +64,7 @@ PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATUR
|
||||
setStream(stream);
|
||||
}
|
||||
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -61,6 +72,7 @@ PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client)
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client, Stream& stream)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -68,6 +80,8 @@ PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client, Stream& s
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
// cppcheck-suppress passedByValue
|
||||
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -76,6 +90,8 @@ PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE,
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
// cppcheck-suppress passedByValue
|
||||
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client,
|
||||
Stream& stream)
|
||||
{
|
||||
@@ -86,6 +102,7 @@ PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE,
|
||||
setStream(stream);
|
||||
}
|
||||
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -93,6 +110,7 @@ PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client)
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client, Stream& stream)
|
||||
{
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@@ -100,6 +118,8 @@ PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client, St
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
// cppcheck-suppress passedByValue
|
||||
PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGNATURE,
|
||||
Client& client)
|
||||
{
|
||||
@@ -109,6 +129,8 @@ PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGN
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
}
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
// cppcheck-suppress passedByValue
|
||||
PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGNATURE,
|
||||
Client& client, Stream& stream)
|
||||
{
|
||||
@@ -337,14 +359,13 @@ bool PubSubClient::loop()
|
||||
if (_client->available()) {
|
||||
uint8_t llen;
|
||||
uint16_t len = readPacket(&llen);
|
||||
uint16_t msgId = 0;
|
||||
uint8_t *payload;
|
||||
if (len > 0) {
|
||||
lastInActivity = t;
|
||||
uint8_t type = buffer[0]&0xF0;
|
||||
if (type == MQTTPUBLISH) {
|
||||
if (callback) {
|
||||
uint16_t tl = (buffer[llen+1]<<8)+buffer[llen+2];
|
||||
uint8_t *payload;
|
||||
char topic[tl+1];
|
||||
for (uint16_t i=0; i<tl; i++) {
|
||||
topic[i] = buffer[llen+3+i];
|
||||
@@ -352,7 +373,7 @@ bool PubSubClient::loop()
|
||||
topic[tl] = 0;
|
||||
// msgId only present for QOS>0
|
||||
if ((buffer[0]&0x06) == MQTTQOS1) {
|
||||
msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1];
|
||||
uint16_t msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1];
|
||||
payload = buffer+llen+3+tl+2;
|
||||
callback(topic,payload,len-llen-3-tl-2);
|
||||
|
||||
@@ -424,8 +445,6 @@ bool PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned i
|
||||
bool PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsigned int plength,
|
||||
bool retained)
|
||||
{
|
||||
uint8_t llen = 0;
|
||||
uint8_t digit;
|
||||
unsigned int rc = 0;
|
||||
uint16_t tlen;
|
||||
unsigned int pos = 0;
|
||||
@@ -446,13 +465,13 @@ bool PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsigned
|
||||
buffer[pos++] = header;
|
||||
len = plength + 2 + tlen;
|
||||
do {
|
||||
uint8_t digit;
|
||||
digit = len % 128;
|
||||
len = len / 128;
|
||||
if (len > 0) {
|
||||
digit |= 0x80;
|
||||
}
|
||||
buffer[pos++] = digit;
|
||||
llen++;
|
||||
} while(len>0);
|
||||
|
||||
pos = writeString(topic,buffer,pos);
|
||||
@@ -472,11 +491,11 @@ bool PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length)
|
||||
{
|
||||
uint8_t lenBuf[4];
|
||||
uint8_t llen = 0;
|
||||
uint8_t digit;
|
||||
uint8_t pos = 0;
|
||||
uint16_t rc;
|
||||
uint16_t len = length;
|
||||
do {
|
||||
uint8_t digit;
|
||||
digit = len % 128;
|
||||
len = len / 128;
|
||||
if (len > 0) {
|
||||
@@ -626,6 +645,7 @@ PubSubClient& PubSubClient::setServer(const char * domain, uint16_t port)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// cppcheck-suppress passedByValue
|
||||
PubSubClient& PubSubClient::setCallback(MQTT_CALLBACK_SIGNATURE)
|
||||
{
|
||||
this->callback = callback;
|
||||
|
||||
@@ -103,7 +103,7 @@ private:
|
||||
int _state;
|
||||
public:
|
||||
PubSubClient(); //!< PubSubClient
|
||||
PubSubClient(Client& client); //!< PubSubClient
|
||||
explicit PubSubClient(Client& client); //!< PubSubClient
|
||||
PubSubClient(IPAddress, uint16_t, Client& client); //!< PubSubClient
|
||||
PubSubClient(IPAddress, uint16_t, Client& client, Stream&); //!< PubSubClient
|
||||
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client); //!< PubSubClient
|
||||
|
||||
@@ -47,6 +47,9 @@ uint8_t SPIFlash::UNIQUEID[8];
|
||||
/// get this from the datasheet of your flash chip
|
||||
/// Example for Atmel-Adesto 4Mbit AT25DF041A: 0x1F44 (page 27: http://www.adestotech.com/sites/default/files/datasheets/doc3668.pdf)
|
||||
/// Example for Winbond 4Mbit W25X40CL: 0xEF30 (page 14: http://www.winbond.com/NR/rdonlyres/6E25084C-0BFE-4B25-903D-AE10221A0929/0/W25X40CL.pdf)
|
||||
// Suppress uninitialized member variable in constructor because some memory can be saved with
|
||||
// on-demand initialization of these members
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
SPIFlash::SPIFlash(uint8_t slaveSelectPin, uint16_t jedecID)
|
||||
{
|
||||
_slaveSelectPin = slaveSelectPin;
|
||||
@@ -248,7 +251,6 @@ void SPIFlash::writeBytes(uint32_t addr, const void* buf, uint16_t len)
|
||||
//SST25 Type of Flash does not support Page Programming but AAI Word Programming
|
||||
uint16_t i=0;
|
||||
uint8_t oddAdr=0;
|
||||
char s[5];
|
||||
|
||||
command(SPIFLASH_AAIWORDPROGRAM, true); // Byte/Page Program
|
||||
SPI.transfer(addr >> 16);
|
||||
|
||||
Reference in New Issue
Block a user