From 4720b2874f8c5699de5be8c73cd68e17e36c5c3d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 14 Dec 2023 07:35:46 -0600 Subject: [PATCH] Cpp-check warnings cleanup (#3014) * cpp-check warnings cleanup * Supressions and more fixes --- src/AccelerometerThread.h | 2 +- src/AmbientLightingThread.h | 2 +- src/Power.cpp | 5 +---- src/PowerFSMThread.h | 2 +- src/mesh/Channels.cpp | 2 +- src/meshUtils.cpp | 7 ++++--- src/modules/NeighborInfoModule.cpp | 4 ++-- src/mqtt/MQTT.cpp | 2 +- suppressions.txt | 5 ++++- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/AccelerometerThread.h b/src/AccelerometerThread.h index da5695368..744f0ad64 100644 --- a/src/AccelerometerThread.h +++ b/src/AccelerometerThread.h @@ -42,7 +42,7 @@ namespace concurrency class AccelerometerThread : public concurrency::OSThread { public: - AccelerometerThread(ScanI2C::DeviceType type = ScanI2C::DeviceType::NONE) : OSThread("AccelerometerThread") + explicit AccelerometerThread(ScanI2C::DeviceType type) : OSThread("AccelerometerThread") { if (accelerometer_found.port == ScanI2C::I2CPort::NO_I2C) { LOG_DEBUG("AccelerometerThread disabling due to no sensors found\n"); diff --git a/src/AmbientLightingThread.h b/src/AmbientLightingThread.h index 0dd0fdf4a..98ccedde4 100644 --- a/src/AmbientLightingThread.h +++ b/src/AmbientLightingThread.h @@ -10,7 +10,7 @@ namespace concurrency class AmbientLightingThread : public concurrency::OSThread { public: - AmbientLightingThread(ScanI2C::DeviceType type) : OSThread("AmbientLightingThread") + explicit AmbientLightingThread(ScanI2C::DeviceType type) : OSThread("AmbientLightingThread") { // Uncomment to test module // moduleConfig.ambient_lighting.led_state = true; diff --git a/src/Power.cpp b/src/Power.cpp index 0fa97b7f0..12e92b3f1 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -402,11 +402,8 @@ bool Power::analogInit() */ bool Power::setup() { - bool found = axpChipInit(); + bool found = axpChipInit() || analogInit(); - if (!found) { - found = analogInit(); - } enabled = found; low_voltage_counter = 0; diff --git a/src/PowerFSMThread.h b/src/PowerFSMThread.h index b757f3abb..584c955aa 100644 --- a/src/PowerFSMThread.h +++ b/src/PowerFSMThread.h @@ -21,7 +21,7 @@ class PowerFSMThread : public OSThread /// If we are in power state we force the CPU to wake every 10ms to check for serial characters (we don't yet wake /// cpu for serial rx - FIXME) - const auto state = powerFSM.getState(); + const State *state = powerFSM.getState(); canSleep = (state != &statePOWER) && (state != &stateSERIAL); if (powerStatus->getHasUSB()) { diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 9974297fa..f3c692e34 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -184,7 +184,7 @@ void Channels::onConfigChanged() { // Make sure the phone hasn't mucked anything up for (int i = 0; i < channelFile.channels_count; i++) { - meshtastic_Channel &ch = fixupChannel(i); + const meshtastic_Channel &ch = fixupChannel(i); if (ch.role == meshtastic_Channel_Role_PRIMARY) primaryIndex = i; diff --git a/src/meshUtils.cpp b/src/meshUtils.cpp index cab05e54b..59d4e6714 100644 --- a/src/meshUtils.cpp +++ b/src/meshUtils.cpp @@ -39,10 +39,11 @@ */ char *strnstr(const char *s, const char *find, size_t slen) { - char c, sc; - size_t len; - + char c; if ((c = *find++) != '\0') { + char sc; + size_t len; + len = strlen(find); do { do { diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index cf2276f0e..4541958fa 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -118,7 +118,7 @@ uint32_t NeighborInfoModule::collectNeighborInfo(meshtastic_NeighborInfo *neighb int num_neighbors = cleanUpNeighbors(); for (int i = 0; i < num_neighbors; i++) { - meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); + const meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); if ((neighborInfo->neighbors_count < MAX_NUM_NEIGHBORS) && (dbEntry->node_id != my_node_id)) { neighborInfo->neighbors[neighborInfo->neighbors_count].node_id = dbEntry->node_id; neighborInfo->neighbors[neighborInfo->neighbors_count].snr = dbEntry->snr; @@ -146,7 +146,7 @@ size_t NeighborInfoModule::cleanUpNeighbors() // Find neighbors to remove std::vector indices_to_remove; for (int i = 0; i < num_neighbors; i++) { - meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); + const meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); // We will remove a neighbor if we haven't heard from them in twice the broadcast interval if ((now - dbEntry->last_rx_time > dbEntry->node_broadcast_interval_secs * 2) && (dbEntry->node_id != my_node_id)) { indices_to_remove.push_back(i); diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index a97aa5255..8c20bfd2f 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -519,10 +519,10 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) // the created jsonObj is immutable after creation, so // we need to do the heavy lifting before assembling it. std::string msgType; - JSONObject msgPayload; JSONObject jsonObj; if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { + JSONObject msgPayload; switch (mp->decoded.portnum) { case meshtastic_PortNum_TEXT_MESSAGE_APP: { msgType = "text"; diff --git a/suppressions.txt b/suppressions.txt index 6cbd38d47..04937523d 100644 --- a/suppressions.txt +++ b/suppressions.txt @@ -50,4 +50,7 @@ virtualCallInConstructor passedByValue:*/RedirectablePrint.h internalAstError:*/CrossPlatformCryptoEngine.cpp -uninitMemberVar:*/AudioThread.h \ No newline at end of file +uninitMemberVar:*/AudioThread.h +// False positive +constVariableReference:*/Channels.cpp +constParameterPointer:*/unishox2.c \ No newline at end of file