Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ba28f75
fix a lot of low level cppcheck warnings
caveman99 Feb 12, 2026
aeae987
simplify the observer pattern, since all the called functions are con…
caveman99 Feb 12, 2026
22eca8d
use arduino macro over std: for numerical values and refactor local v…
caveman99 Feb 12, 2026
ef8ee02
trunk'd
caveman99 Feb 12, 2026
05f6724
oh, so Cppcheck actually complained about const pointers not being co…
caveman99 Feb 12, 2026
6333971
trunk'd again
caveman99 Feb 12, 2026
8c08e25
fix a lot of low level cppcheck warnings
caveman99 Feb 12, 2026
6d85a68
simplify the observer pattern, since all the called functions are con…
caveman99 Feb 12, 2026
fce912a
use arduino macro over std: for numerical values and refactor local v…
caveman99 Feb 12, 2026
18bbb6f
trunk'd
caveman99 Feb 12, 2026
ac83983
oh, so Cppcheck actually complained about const pointers not being co…
caveman99 Feb 12, 2026
eb39348
trunk'd again
caveman99 Feb 12, 2026
3d71c30
slowly getting out of ifdef hell
caveman99 Feb 12, 2026
fe040e8
Merge branch 'fix-cppcheck' of https://github.com/meshtastic/firmware…
caveman99 Feb 12, 2026
7163195
remove errorneous checkin
caveman99 Feb 12, 2026
f097763
fix inkHUD warnings as well
caveman99 Feb 13, 2026
04a182b
Merge branch 'fix-cppcheck' of https://github.com/meshtastic/firmware…
caveman99 Feb 13, 2026
cde51a9
last 2 check warnings
caveman99 Feb 13, 2026
61f8faf
git checks should fail on low defects from now on
caveman99 Feb 13, 2026
d9c06da
Merge branch 'develop' into fix-cppcheck
caveman99 Feb 16, 2026
4dfad37
trunk
caveman99 Feb 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ bool Power::setup()
} else if (analogInit()) {
found = true;
}

#ifdef NRF_APM
found = true;
if (!found)
Comment thread
caveman99 marked this conversation as resolved.
Resolved
found = true;
#endif
#ifdef EXT_PWR_DETECT
attachInterrupt(
Expand Down Expand Up @@ -846,8 +846,10 @@ void Power::readPowerStatus()

if (batteryLevel) {
hasBattery = batteryLevel->isBatteryConnect() ? OptTrue : OptFalse;
#ifndef NRF_APM
usbPowered = batteryLevel->isVbusIn() ? OptTrue : OptFalse;
isChargingNow = batteryLevel->isCharging() ? OptTrue : OptFalse;
#endif
if (hasBattery) {
batteryVoltageMv = batteryLevel->getBattVoltage();
// If the AXP192 returns a valid battery percentage, use it
Expand Down
2 changes: 1 addition & 1 deletion src/gps/RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ const char *RtcName(RTCQuality quality)
* @param t The time to potentially set the RTC to.
* @return True if the RTC was set to the provided time, false otherwise.
*/
RTCSetResult perhapsSetRTC(RTCQuality q, struct tm &t)
RTCSetResult perhapsSetRTC(RTCQuality q, const struct tm &t)
{
/* Convert to unix time
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970
Expand Down
2 changes: 1 addition & 1 deletion src/gps/RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern uint32_t lastSetFromPhoneNtpOrGps;

/// If we haven't yet set our RTC this boot, set it from a GPS derived time
RTCSetResult perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpdate = false);
RTCSetResult perhapsSetRTC(RTCQuality q, struct tm &t);
RTCSetResult perhapsSetRTC(RTCQuality q, const struct tm &t);

/// Return a string name for the quality
const char *RtcName(RTCQuality quality);
Expand Down
12 changes: 6 additions & 6 deletions src/graphics/draw/MenuHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void menuHandler::messageResponseMenu()
// If viewing ALL chats, hide “Mute Chat”
if (mode != graphics::MessageRenderer::ThreadMode::ALL && mode != graphics::MessageRenderer::ThreadMode::DIRECT) {
const uint8_t chIndex = (threadChannel != 0) ? (uint8_t)threadChannel : channels.getPrimaryIndex();
auto &chan = channels.getByIndex(chIndex);
const auto &chan = channels.getByIndex(chIndex);

optionsArray[options] = chan.settings.module_settings.is_muted ? "Unmute Channel" : "Mute Channel";
optionsEnumArray[options++] = MuteChannel;
Expand Down Expand Up @@ -831,7 +831,7 @@ void menuHandler::messageViewModeMenu()
// Gather unique peers
auto dms = messageStore.getDirectMessages();
std::vector<uint32_t> uniquePeers;
for (auto &m : dms) {
for (const auto &m : dms) {
uint32_t peer = (m.sender == nodeDB->getNodeNum()) ? m.dest : m.sender;
if (peer != nodeDB->getNodeNum() && std::find(uniquePeers.begin(), uniquePeers.end(), peer) == uniquePeers.end())
uniquePeers.push_back(peer);
Expand Down Expand Up @@ -1397,7 +1397,7 @@ void menuHandler::manageNodeMenu()
}

if (selected == Favorite) {
auto n = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
const auto *n = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
if (!n) {
return;
}
Expand Down Expand Up @@ -2444,7 +2444,7 @@ void menuHandler::frameTogglesMenu()
nodelist_hopsignal,
nodelist_distance,
nodelist_bearings,
gps,
gps_position,
lora,
clock,
show_favorites,
Expand Down Expand Up @@ -2482,7 +2482,7 @@ void menuHandler::frameTogglesMenu()
#endif

optionsArray[options] = screen->isFrameHidden("gps") ? "Show Position" : "Hide Position";
optionsEnumArray[options++] = gps;
optionsEnumArray[options++] = gps_position;
#endif

optionsArray[options] = screen->isFrameHidden("lora") ? "Show LoRa" : "Hide LoRa";
Expand Down Expand Up @@ -2545,7 +2545,7 @@ void menuHandler::frameTogglesMenu()
screen->toggleFrameVisibility("nodelist_bearings");
menuHandler::menuQueue = menuHandler::FrameToggles;
screen->runNow();
} else if (selected == gps) {
} else if (selected == gps_position) {
screen->toggleFrameVisibility("gps");
menuHandler::menuQueue = menuHandler::FrameToggles;
screen->runNow();
Expand Down
23 changes: 10 additions & 13 deletions src/graphics/draw/NodeListRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ unsigned long getModeCycleIntervalMs()

int calculateMaxScroll(int totalEntries, int visibleRows)
{
return std::max(0, (totalEntries - 1) / (visibleRows * 2));
return max(0, (totalEntries - 1) / (visibleRows * 2));
}

void drawColumnSeparator(OLEDDisplay *display, int16_t x, int16_t yStart, int16_t yEnd)
Expand All @@ -187,13 +187,12 @@ void drawScrollbar(OLEDDisplay *display, int visibleNodeRows, int totalEntries,
if (totalEntries <= visibleNodeRows * columns)
return;

int scrollbarX = display->getWidth() - 2;
int scrollbarHeight = display->getHeight() - scrollStartY - 10;
int thumbHeight = std::max(4, (scrollbarHeight * visibleNodeRows * columns) / totalEntries);
int perPage = visibleNodeRows * columns;
int maxScroll = std::max(0, (totalEntries - 1) / perPage);
int thumbY = scrollStartY + (scrollIndex * (scrollbarHeight - thumbHeight)) / std::max(1, maxScroll);
int thumbHeight = max(4, (scrollbarHeight * visibleNodeRows * columns) / totalEntries);
int thumbY = scrollStartY + (scrollIndex * (scrollbarHeight - thumbHeight)) /
max(1, max(0, (totalEntries - 1) / (visibleNodeRows * columns)));

int scrollbarX = display->getWidth() - 2;
for (int i = 0; i < thumbHeight; i++) {
display->setPixel(scrollbarX, thumbY + i);
}
Expand Down Expand Up @@ -556,13 +555,13 @@ void drawNodeListScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t

int maxScroll = 0;
if (perPage > 0) {
maxScroll = std::max(0, (totalEntries - 1) / perPage);
maxScroll = max(0, (totalEntries - 1) / perPage);
}

if (scrollIndex > maxScroll)
scrollIndex = maxScroll;
int startIndex = scrollIndex * visibleNodeRows * totalColumns;
int endIndex = std::min(startIndex + visibleNodeRows * totalColumns, totalEntries);
int endIndex = min(startIndex + visibleNodeRows * totalColumns, totalEntries);
int yOffset = 0;
int col = 0;
int lastNodeY = y;
Expand All @@ -580,7 +579,7 @@ void drawNodeListScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t
if (extras)
extras(display, node, xPos, yPos, columnWidth, heading, lat, lon);

lastNodeY = std::max(lastNodeY, yPos + FONT_HEIGHT_SMALL);
lastNodeY = max(lastNodeY, yPos + FONT_HEIGHT_SMALL);
yOffset += rowYOffset;
shownCount++;
rowCount++;
Expand Down Expand Up @@ -613,13 +612,11 @@ void drawNodeListScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t
if (millis() - popupTime < POPUP_DURATION_MS) {
popupTotal = totalEntries;

int perPage = visibleNodeRows * totalColumns;

popupStart = startIndex + 1;
popupEnd = std::min(startIndex + perPage, totalEntries);
popupEnd = min(startIndex + perPage, totalEntries);

popupPage = (scrollIndex + 1);
popupMaxPage = std::max(1, (totalEntries + perPage - 1) / perPage);
popupMaxPage = max(1, (totalEntries + perPage - 1) / perPage);

char buf[32];
snprintf(buf, sizeof(buf), "%d-%d/%d Pg %d/%d", popupStart, popupEnd, popupTotal, popupPage, popupMaxPage);
Expand Down
4 changes: 3 additions & 1 deletion src/graphics/draw/UIRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ void UIRenderer::drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const mes
// **********************
// * Favorite Node Info *
// **********************
void UIRenderer::drawNodeInfo(OLEDDisplay *display, const OLEDDisplayUiState *state, int16_t x, int16_t y)
// cppcheck-suppress constParameterPointer; signature must match FrameCallback typedef from OLEDDisplayUi library
void UIRenderer::drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
if (favoritedNodes.empty())
return;
Expand Down Expand Up @@ -1388,6 +1389,7 @@ static int8_t lastFrameIndex = -1;
static uint32_t lastFrameChangeTime = 0;
constexpr uint32_t ICON_DISPLAY_DURATION_MS = 2000;

// cppcheck-suppress constParameterPointer; signature must match OverlayCallback typedef from OLEDDisplayUi library
void UIRenderer::drawNavigationBar(OLEDDisplay *display, OLEDDisplayUiState *state)
{
int currentFrame = state->currentFrame;
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/draw/UIRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class UIRenderer
// Navigation bar overlay
static void drawNavigationBar(OLEDDisplay *display, OLEDDisplayUiState *state);

static void drawNodeInfo(OLEDDisplay *display, const OLEDDisplayUiState *state, int16_t x, int16_t y);
static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);

static void drawDeviceFocused(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);

Expand Down
3 changes: 1 addition & 2 deletions src/input/TCA8418Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void TCA8418Keyboard::pressed(uint8_t key)
if (state == Init || state == Busy) {
return;
}
uint8_t next_key = 0;
int row = (key - 1) / 10;
int col = (key - 1) % 10;

Expand All @@ -72,7 +71,7 @@ void TCA8418Keyboard::pressed(uint8_t key)
}

// Compute key index based on dynamic row/column
next_key = row * _TCA8418_COLS + col;
next_key = (int8_t)(row * _TCA8418_COLS + col);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a uint8_t?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was also one of my question marks. i'll review once more

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. next_key and last_key are class variables defined as int_8 - the original issue was variable shadowing inside the pressed() function by redefining as uint8 and then signed/unsigned comaprison to int8 last_key.

Apparently last_key can be <0 (checked in release()) - are they prone to go over 128? If so we shouold increase to INt16


// LOG_DEBUG("TCA8418: Key %u -> Next Key %u", key, next_key);

Expand Down
14 changes: 5 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ static OSThread *powerFSMthread;
OSThread *ambientLightingThread;

RadioInterface *rIf = NULL;
#ifdef ARCH_PORTDUINO
RadioLibHal *RadioLibHAL = NULL;
#endif

/**
* Some platforms (nrf52) might provide an alterate version that suppresses calling delay from sleep.
Expand Down Expand Up @@ -725,17 +723,15 @@ void setup()
playStartMelody();

#if HAS_SCREEN
// fixed screen override?
if (config.display.oled != meshtastic_Config_DisplayConfig_OledType_OLED_AUTO)
screen_model = config.display.oled;

// fixed screen override?
#if defined(USE_SH1107)
screen_model = meshtastic_Config_DisplayConfig_OledType_OLED_SH1107; // set dimension of 128x128
screen_geometry = GEOMETRY_128_128;
#endif

#if defined(USE_SH1107_128_64)
#elif defined(USE_SH1107_128_64)
screen_model = meshtastic_Config_DisplayConfig_OledType_OLED_SH1107; // keep dimension of 128x64
#else
if (config.display.oled != meshtastic_Config_DisplayConfig_OledType_OLED_AUTO)
screen_model = config.display.oled;
#endif
#endif

Expand Down
12 changes: 7 additions & 5 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,26 +814,28 @@ void NodeDB::installDefaultModuleConfig()
moduleConfig.has_store_forward = true;
moduleConfig.has_telemetry = true;
moduleConfig.has_external_notification = true;
#if defined(PIN_BUZZER)
#if defined(PIN_BUZZER) || defined(PIN_VIBRATION) || defined(LED_NOTIFICATION)
moduleConfig.external_notification.enabled = true;
#endif
#if defined(PIN_BUZZER)
moduleConfig.external_notification.output_buzzer = PIN_BUZZER;
moduleConfig.external_notification.use_pwm = true;
moduleConfig.external_notification.alert_message_buzzer = true;
moduleConfig.external_notification.nag_timeout = default_ringtone_nag_secs;
#endif
#if defined(PIN_VIBRATION)
moduleConfig.external_notification.enabled = true;
moduleConfig.external_notification.output_vibra = PIN_VIBRATION;
moduleConfig.external_notification.alert_message_vibra = true;
moduleConfig.external_notification.output_ms = 500;
moduleConfig.external_notification.nag_timeout = 2;
#endif
#if defined(LED_NOTIFICATION)
moduleConfig.external_notification.enabled = true;
moduleConfig.external_notification.output = LED_NOTIFICATION;
moduleConfig.external_notification.active = LED_STATE_ON;
moduleConfig.external_notification.alert_message = true;
moduleConfig.external_notification.output_ms = 1000;
#endif
#if defined(PIN_VIBRATION)
moduleConfig.external_notification.nag_timeout = 2;
#elif defined(PIN_BUZZER) || defined(LED_NOTIFICATION)
moduleConfig.external_notification.nag_timeout = default_ringtone_nag_secs;
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/mesh/PacketHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void PacketHistory::removeRelayer(const uint8_t relayer, const uint32_t id, cons
}

// Getters and setters for hop limit fields packed in hop_limit
inline uint8_t PacketHistory::getHighestHopLimit(PacketRecord &r)
inline uint8_t PacketHistory::getHighestHopLimit(const PacketRecord &r)
{
return r.hop_limit & HOP_LIMIT_HIGHEST_MASK;
}
Expand All @@ -449,7 +449,7 @@ inline void PacketHistory::setHighestHopLimit(PacketRecord &r, uint8_t hopLimit)
r.hop_limit = (r.hop_limit & ~HOP_LIMIT_HIGHEST_MASK) | (hopLimit & HOP_LIMIT_HIGHEST_MASK);
}

inline uint8_t PacketHistory::getOurTxHopLimit(PacketRecord &r)
inline uint8_t PacketHistory::getOurTxHopLimit(const PacketRecord &r)
{
return (r.hop_limit & HOP_LIMIT_OUR_TX_MASK) >> HOP_LIMIT_OUR_TX_SHIFT;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/PacketHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class PacketHistory
* @return true if node was indeed a relayer, false if not */
bool wasRelayer(const uint8_t relayer, const PacketRecord &r, bool *wasSole = nullptr);

uint8_t getHighestHopLimit(PacketRecord &r);
uint8_t getHighestHopLimit(const PacketRecord &r);
void setHighestHopLimit(PacketRecord &r, uint8_t hopLimit);
uint8_t getOurTxHopLimit(PacketRecord &r);
uint8_t getOurTxHopLimit(const PacketRecord &r);
void setOurTxHopLimit(PacketRecord &r, uint8_t hopLimit);

PacketHistory(const PacketHistory &); // non construction-copyable
Expand Down
Loading