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:
parent
3e28724b62
commit
1a53dccebd
@ -382,7 +382,7 @@ void EpubReaderActivity::renderStatusBar() const {
|
|||||||
const auto tocItem = epub->getTocItem(tocIndex);
|
const auto tocItem = epub->getTocItem(tocIndex);
|
||||||
title = tocItem.title;
|
title = tocItem.title;
|
||||||
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
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) + "...";
|
title = title.substr(0, title.length() - 8) + "...";
|
||||||
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user