Fix title truncation underflow when title is shorter than 8 chars

The status bar title truncation loop could crash if the title length
was less than 8 characters, as title.length() - 8 would underflow
(size_t is unsigned). Added a length check to prevent this.
This commit is contained in:
IFAKA 2025-12-19 01:07:38 +01:00
parent d86b3fe134
commit 2b860d9067

View File

@ -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());
} }