style: fix all cppcheck warnings
Some checks failed
CI / build (push) Failing after 3m20s

- Fix ignored return value in TxtReaderActivity
- Remove unused variables across multiple files
- Add const correctness to DictionaryMargins and EpubReaderActivity
- Replace inefficient substr patterns with resize+append
- Use STL algorithms (find_if, any_of, copy_if, transform) where applicable
- Remove dead sync placeholder code in EpubReaderChapterSelectionActivity
- Add cppcheck suppression for ValueFlow analysis limitation

Resolves all low, medium, and high severity cppcheck defects.
This commit is contained in:
cottongin
2026-01-28 09:45:42 -05:00
parent fe446d4690
commit bd95bfd44d
13 changed files with 66 additions and 102 deletions

View File

@@ -386,9 +386,7 @@ void EpubReaderActivity::loop() {
[this](QuickMenuAction action) {
// Cache values before exitActivity
EpubReaderActivity* self = this;
GfxRenderer& cachedRenderer = renderer;
MappedInputManager& cachedMappedInput = mappedInput;
Section* cachedSection = section.get();
const Section* cachedSection = section.get();
SemaphoreHandle_t cachedMutex = renderingMutex;
exitActivity();
@@ -938,7 +936,8 @@ void EpubReaderActivity::renderEndOfBookPrompt() {
// Book title (truncated if needed)
std::string bookTitle = epub->getTitle();
if (bookTitle.length() > 30) {
bookTitle = bookTitle.substr(0, 27) + "...";
bookTitle.resize(27);
bookTitle += "...";
}
renderer.drawCenteredText(UI_10_FONT_ID, 120, bookTitle.c_str());

View File

@@ -10,7 +10,12 @@ namespace {
constexpr int SKIP_PAGE_MS = 700;
} // namespace
bool EpubReaderChapterSelectionActivity::hasSyncOption() const { return false; }
// Sync feature is currently disabled - will be enabled when implemented
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
bool EpubReaderChapterSelectionActivity::hasSyncOption() const {
// TODO: Return true when sync credentials are configured
return false;
}
int EpubReaderChapterSelectionActivity::getTotalItems() const {
// Add 2 for sync options (top and bottom) if credentials are configured
@@ -18,12 +23,6 @@ int EpubReaderChapterSelectionActivity::getTotalItems() const {
return epub->getTocItemsCount() + syncCount;
}
bool EpubReaderChapterSelectionActivity::isSyncItem(int index) const {
if (!hasSyncOption()) return false;
// First item and last item are sync options
return index == 0 || index == getTotalItems() - 1;
}
int EpubReaderChapterSelectionActivity::tocIndexFromItemIndex(int itemIndex) const {
// Account for the sync option at the top
const int offset = hasSyncOption() ? 1 : 0;
@@ -94,10 +93,6 @@ void EpubReaderChapterSelectionActivity::onExit() {
renderingMutex = nullptr;
}
void EpubReaderChapterSelectionActivity::launchSyncActivity() {
// KOReader sync functionality removed
}
void EpubReaderChapterSelectionActivity::loop() {
if (subActivity) {
subActivity->loop();
@@ -114,13 +109,7 @@ void EpubReaderChapterSelectionActivity::loop() {
const int totalItems = getTotalItems();
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
// Check if sync option is selected (first or last item)
if (isSyncItem(selectorIndex)) {
launchSyncActivity();
return;
}
// Get TOC index (account for top sync offset)
// Get TOC index (account for top sync offset if enabled)
const int tocIndex = tocIndexFromItemIndex(selectorIndex);
const auto newSpineIndex = epub->getSpineIndexForTocIndex(tocIndex);
if (newSpineIndex == -1) {
@@ -182,19 +171,13 @@ void EpubReaderChapterSelectionActivity::renderScreen() {
const int displayY = 60 + bezelTop + (itemIndex % pageItems) * 30;
const bool isSelected = (itemIndex == selectorIndex);
if (isSyncItem(itemIndex)) {
// Draw sync option (at top or bottom)
renderer.drawText(UI_10_FONT_ID, 20 + bezelLeft, displayY, ">> Sync Progress", !isSelected);
} else {
// Draw TOC item (account for top sync offset)
const int tocIndex = tocIndexFromItemIndex(itemIndex);
auto item = epub->getTocItem(tocIndex);
const int indentSize = 20 + bezelLeft + (item.level - 1) * 15;
const std::string chapterName =
renderer.truncatedText(UI_10_FONT_ID, item.title.c_str(), pageWidth - 40 - bezelLeft - bezelRight - indentSize + 20 + bezelLeft);
renderer.drawText(UI_10_FONT_ID, indentSize, 60 + bezelTop + (tocIndex % pageItems) * 30, chapterName.c_str(),
tocIndex != selectorIndex);
}
// Draw TOC item
const int tocIndex = tocIndexFromItemIndex(itemIndex);
auto item = epub->getTocItem(tocIndex);
const int indentSize = 20 + bezelLeft + (item.level - 1) * 15;
const std::string chapterName =
renderer.truncatedText(UI_10_FONT_ID, item.title.c_str(), pageWidth - 40 - bezelLeft - bezelRight - indentSize + 20 + bezelLeft);
renderer.drawText(UI_10_FONT_ID, indentSize, displayY, chapterName.c_str(), !isSelected);
}
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");

View File

@@ -30,18 +30,15 @@ class EpubReaderChapterSelectionActivity final : public ActivityWithSubactivity
int getTotalItems() const;
// Check if sync option is available (credentials configured)
// Note: Currently always returns false - placeholder for future sync feature
bool hasSyncOption() const;
// Check if given item index is a sync option (first or last)
bool isSyncItem(int index) const;
// Convert item index to TOC index (accounting for top sync option offset)
int tocIndexFromItemIndex(int itemIndex) const;
static void taskTrampoline(void* param);
[[noreturn]] void displayTaskLoop();
void renderScreen();
void launchSyncActivity();
public:
explicit EpubReaderChapterSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,

View File

@@ -88,7 +88,7 @@ void TxtReaderActivity::onEnter() {
renderer.displayBuffer(EInkDisplay::FAST_REFRESH);
// Generate covers with progress callback
txt->generateAllCovers([&](int percent) {
(void)txt->generateAllCovers([&](int percent) {
const unsigned long now = millis();
if ((now - lastUpdate) >= 3000) {
lastUpdate = now;
@@ -888,7 +888,8 @@ void TxtReaderActivity::renderEndOfBookPrompt() {
filename = filename.substr(lastSlash + 1);
}
if (filename.length() > 30) {
filename = filename.substr(0, 27) + "...";
filename.resize(27);
filename += "...";
}
renderer.drawCenteredText(UI_10_FONT_ID, 120, filename.c_str());