From 1a53dccebd126ea4c2cc2e593667c64d9954dc57 Mon Sep 17 00:00:00 2001 From: IFAKA <99131130+IFAKA@users.noreply.github.com> Date: Fri, 19 Dec 2025 13:23:43 +0100 Subject: [PATCH] Fix title truncation crash for short titles (#63) ## Problem The status bar title truncation loop crashes when the chapter title is shorter than 8 characters. ```cpp // title.length() - 8 underflows when length < 8 (size_t is unsigned) title = title.substr(0, title.length() - 8) + "..."; ``` ## Fix Added a length guard to skip truncation for titles that are too short to truncate safely. ## Testing - Builds successfully with `pio run` - Affects: `src/activities/reader/EpubReaderActivity.cpp` --- src/activities/reader/EpubReaderActivity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index f4e45363..3bae96d6 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -382,7 +382,7 @@ void EpubReaderActivity::renderStatusBar() const { const auto tocItem = epub->getTocItem(tocIndex); title = tocItem.title; titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str()); - while (titleWidth > availableTextWidth) { + while (titleWidth > availableTextWidth && title.length() > 11) { title = title.substr(0, title.length() - 8) + "..."; titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str()); }