fix some cppcheck warnings

pull/1138/head
Mike Kinney 2022-01-24 07:00:14 +00:00
rodzic 8a79ede285
commit b3210f6c2c
20 zmienionych plików z 82 dodań i 45 usunięć

2
.gitignore vendored
Wyświetl plik

@ -26,3 +26,5 @@ __pycache__
*.swp
*.swo
*~
venv/

18
bin/check-all.sh 100755
Wyświetl plik

@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Note: This is a prototype for how we could add static code analysis to the CI.
set -e
VERSION=`bin/buildinfo.py long`
# The shell vars the build tool expects to find
export APP_VERSION=$VERSION
# only check high and medium in our source
# TODO: only doing tbeam (to start; add all/more later)
pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" -e tbeam --skip-packages --severity=medium --severity=high --pattern="src/"
return_code=$?
# TODO: not sure why return_code is 0
echo "return_code:${return_code}"

Wyświetl plik

@ -149,7 +149,10 @@ class AnalogBatteryLevel : public HasBatteryLevel
AnalogBatteryLevel analogLevel;
Power::Power() : OSThread("Power") {}
Power::Power() : OSThread("Power") {
statusHandler = {};
low_voltage_counter = 0;
}
bool Power::analogInit()
{

Wyświetl plik

@ -2,7 +2,7 @@
#include "NodeDB.h"
#include "configuration.h"
AirTime *airTime;
AirTime *airTime = NULL;
// Don't read out of this directly. Use the helper functions.
@ -117,7 +117,9 @@ float AirTime::utilizationTXPercent()
return (float(sum) / float(MS_IN_HOUR)) * 100;
}
AirTime::AirTime() : concurrency::OSThread("AirTime") {}
AirTime::AirTime() : concurrency::OSThread("AirTime") {
airtimes = {};
}
int32_t AirTime::runOnce()
{
@ -183,4 +185,4 @@ int32_t AirTime::runOnce()
DEBUG_MSG("\n");
*/
return (1000 * 1);
}
}

Wyświetl plik

@ -49,8 +49,8 @@ class AirTime : private concurrency::OSThread
float utilizationTXPercent();
float UtilizationPercentTX();
uint32_t channelUtilization[CHANNEL_UTILIZATION_PERIODS];
uint32_t utilizationTX[MINUTES_IN_HOUR];
uint32_t channelUtilization[CHANNEL_UTILIZATION_PERIODS] = {0};
uint32_t utilizationTX[MINUTES_IN_HOUR] = {0};
void airtimeRotatePeriod();
uint8_t getPeriodsToLog();
@ -79,4 +79,4 @@ class AirTime : private concurrency::OSThread
virtual int32_t runOnce() override;
};
extern AirTime *airTime;
extern AirTime *airTime;

Wyświetl plik

@ -14,9 +14,9 @@
*/
class SimpleAllocator
{
uint8_t bytes[POOL_SIZE];
uint8_t bytes[POOL_SIZE] = {};
uint32_t nextFree;
uint32_t nextFree = 0;
public:
SimpleAllocator();

Wyświetl plik

@ -447,4 +447,4 @@ std::shared_ptr<GeoCoord> GeoCoord::pointAtDistance(double bearing, double range
return std::make_shared<GeoCoord>(double(lat), double(lon), this->getAltitude());
}
}

Wyświetl plik

@ -86,11 +86,11 @@ class GeoCoord {
int32_t _longitude = 0;
int32_t _altitude = 0;
DMS _dms;
UTM _utm;
MGRS _mgrs;
OSGR _osgr;
OLC _olc;
DMS _dms = {};
UTM _utm = {};
MGRS _mgrs = {};
OSGR _osgr = {};
OLC _olc = {};
bool _dirty = true;

Wyświetl plik

@ -449,10 +449,10 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
if (gpsFormat == GpsCoordinateFormat_GpsFormatDec) { // Decimal Degrees
sprintf(coordinateLine, "%f %f", geoCoord.getLatitude() * 1e-7, geoCoord.getLongitude() * 1e-7);
} else if (gpsFormat == GpsCoordinateFormat_GpsFormatUTM) { // Universal Transverse Mercator
sprintf(coordinateLine, "%2i%1c %06i %07i", geoCoord.getUTMZone(), geoCoord.getUTMBand(),
sprintf(coordinateLine, "%2i%1c %06u %07u", geoCoord.getUTMZone(), geoCoord.getUTMBand(),
geoCoord.getUTMEasting(), geoCoord.getUTMNorthing());
} else if (gpsFormat == GpsCoordinateFormat_GpsFormatMGRS) { // Military Grid Reference System
sprintf(coordinateLine, "%2i%1c %1c%1c %05i %05i", geoCoord.getMGRSZone(), geoCoord.getMGRSBand(),
sprintf(coordinateLine, "%2i%1c %1c%1c %05u %05u", geoCoord.getMGRSZone(), geoCoord.getMGRSBand(),
geoCoord.getMGRSEast100k(), geoCoord.getMGRSNorth100k(), geoCoord.getMGRSEasting(),
geoCoord.getMGRSNorthing());
} else if (gpsFormat == GpsCoordinateFormat_GpsFormatOLC) { // Open Location Code
@ -461,7 +461,7 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
if (geoCoord.getOSGRE100k() == 'I' || geoCoord.getOSGRN100k() == 'I') // OSGR is only valid around the UK region
sprintf(coordinateLine, "%s", "Out of Boundary");
else
sprintf(coordinateLine, "%1c%1c %05i %05i", geoCoord.getOSGRE100k(), geoCoord.getOSGRN100k(),
sprintf(coordinateLine, "%1c%1c %05u %05u", geoCoord.getOSGRE100k(), geoCoord.getOSGRN100k(),
geoCoord.getOSGREasting(), geoCoord.getOSGRNorthing());
}
@ -479,9 +479,9 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
} else {
char latLine[22];
char lonLine[22];
sprintf(latLine, "%2i° %2i' %2.4f\" %1c", geoCoord.getDMSLatDeg(), geoCoord.getDMSLatMin(), geoCoord.getDMSLatSec(),
sprintf(latLine, "%2i° %2i' %2u\" %1c", geoCoord.getDMSLatDeg(), geoCoord.getDMSLatMin(), geoCoord.getDMSLatSec(),
geoCoord.getDMSLatCP());
sprintf(lonLine, "%3i° %2i' %2.4f\" %1c", geoCoord.getDMSLonDeg(), geoCoord.getDMSLonMin(), geoCoord.getDMSLonSec(),
sprintf(lonLine, "%3i° %2i' %2u\" %1c", geoCoord.getDMSLonDeg(), geoCoord.getDMSLonMin(), geoCoord.getDMSLonSec(),
geoCoord.getDMSLonCP());
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(latLine))) / 2, y - FONT_HEIGHT_SMALL * 1, latLine);
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(lonLine))) / 2, y, lonLine);
@ -1050,7 +1050,7 @@ void Screen::handleStartBluetoothPinScreen(uint32_t pin)
static FrameCallback btFrames[] = {drawFrameBluetooth};
snprintf(btPIN, sizeof(btPIN), "%06lu", pin);
snprintf(btPIN, sizeof(btPIN), "%06u", pin);
ui.disableAllIndicators();
ui.setFrames(btFrames, 1);

Wyświetl plik

@ -48,10 +48,10 @@ class RotaryEncoderInterruptBase :
volatile RotaryEncoderInterruptBaseActionType action = ROTARY_ACTION_NONE;
private:
uint8_t _pinA;
uint8_t _pinB;
char _eventCw;
char _eventCcw;
char _eventPressed;
uint8_t _pinA = 0;
uint8_t _pinB = 0;
char _eventCw = InputEventChar_KEY_NONE;
char _eventCcw = InputEventChar_KEY_NONE;
char _eventPressed = InputEventChar_KEY_NONE;
const char *_originName;
};
};

Wyświetl plik

@ -20,9 +20,9 @@ class CryptoEngine
{
protected:
/** Our per packet nonce */
uint8_t nonce[16];
uint8_t nonce[16] = {0};
CryptoKey key;
CryptoKey key = {};
public:
virtual ~CryptoEngine() {}

Wyświetl plik

@ -45,7 +45,7 @@ class PhoneAPI
/// We temporarily keep the nodeInfo here between the call to available and getFromRadio
const NodeInfo *nodeInfoForPhone = NULL;
ToRadio toRadioScratch; // this is a static scratch object, any data must be copied elsewhere before returning
ToRadio toRadioScratch = {0}; // this is a static scratch object, any data must be copied elsewhere before returning
/// Use to ensure that clients don't get confused about old messages from the radio
uint32_t config_nonce = 0;
@ -86,7 +86,7 @@ class PhoneAPI
protected:
/// Our fromradio packet while it is being assembled
FromRadio fromRadioScratch;
FromRadio fromRadioScratch = {};
/** the last msec we heard from the client on the other side of this link */
uint32_t lastContactMsec = 0;

Wyświetl plik

@ -9,7 +9,7 @@
*/
class RF95Interface : public RadioLibInterface
{
RadioLibRF95 *lora; // Either a RFM95 or RFM96 depending on what was stuffed on this board
RadioLibRF95 *lora = NULL; // Either a RFM95 or RFM96 depending on what was stuffed on this board
public:
RF95Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass &spi);
@ -63,4 +63,4 @@ class RF95Interface : public RadioLibInterface
private:
/** Some boards require GPIO control of tx vs rx paths */
void setTransmitEnable(bool txon);
};
};

Wyświetl plik

@ -95,7 +95,7 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified
PhysicalLayer *iface;
/// are _trying_ to receive a packet currently (note - we might just be waiting for one)
bool isReceiving;
bool isReceiving = false;
public:
/** Our ISR code currently needs this to find our active instance
@ -183,4 +183,4 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified
virtual void addReceiveMetadata(MeshPacket *mp) = 0;
virtual void setStandby() = 0;
};
};

Wyświetl plik

@ -35,7 +35,7 @@ class StreamAPI : public PhoneAPI, protected concurrency::OSThread
*/
Stream *stream;
uint8_t rxBuf[MAX_STREAM_BUF_SIZE];
uint8_t rxBuf[MAX_STREAM_BUF_SIZE] = {0};
size_t rxPtr = 0;
/// time of last rx, used, to slow down our polling if we haven't heard from anyone
@ -81,5 +81,5 @@ class StreamAPI : public PhoneAPI, protected concurrency::OSThread
bool canWrite = true;
/// Subclasses can use this scratch buffer if they wish
uint8_t txBuf[MAX_STREAM_BUF_SIZE];
};
uint8_t txBuf[MAX_STREAM_BUF_SIZE] = {0};
};

Wyświetl plik

@ -35,10 +35,10 @@ class EnvironmentalMeasurementPlugin : private concurrency::OSThread, public Pro
private:
float CelsiusToFarenheit(float c);
bool firstTime = 1;
DHT *dht;
OneWire *oneWire;
DS18B20 *ds18b20;
DHT *dht = NULL;
OneWire *oneWire = NULL;
DS18B20 *ds18b20 = NULL;
Adafruit_BME280 bme;
const MeshPacket *lastMeasurementPacket;
uint32_t sensor_read_error_count = 0;
};
};

Wyświetl plik

@ -25,7 +25,7 @@ extern RangeTestPlugin *rangeTestPlugin;
*/
class RangeTestPluginRadio : public SinglePortPlugin
{
uint32_t lastRxID;
uint32_t lastRxID = 0;
public:
RangeTestPluginRadio() : SinglePortPlugin("RangeTestPluginRadio", PortNum_TEXT_MESSAGE_APP) {}

Wyświetl plik

@ -25,7 +25,7 @@ extern SerialPlugin *serialPlugin;
*/
class SerialPluginRadio : public SinglePortPlugin
{
uint32_t lastRxID;
uint32_t lastRxID = 0;
public:
/*

Wyświetl plik

@ -121,7 +121,7 @@ void StoreForwardPlugin::historySend(uint32_t msAgo, uint32_t to)
uint32_t queueSize = storeForwardPlugin->historyQueueCreate(msAgo, to);
if (queueSize) {
snprintf(this->routerMessage, 80, "** S&F - Sending %d message(s)", queueSize);
snprintf(this->routerMessage, 80, "** S&F - Sending %u message(s)", queueSize);
storeForwardPlugin->sendMessage(to, this->routerMessage);
this->busy = true; // runOnce() will pickup the next steps once busy = true.

12
suppressions.txt 100644
Wyświetl plik

@ -0,0 +1,12 @@
// cppcheck suppressions
assertWithSideEffect
// TODO: need to come back to these
duplInheritedMember
// most likely due to a cppcheck configuration issue (like missing an include)
syntaxError
// ignore stuff that is not ours
*:.pio/*
*:*/libdeps/*