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`
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user