Update src/activities/reader/EpubReaderActivity.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Arthur Tazhitdinov 2026-02-02 19:42:22 +03:00 committed by GitHub
parent a6fd503f94
commit 17c20db930
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -253,7 +253,10 @@ void EpubReaderActivity::jumpToPercent(int percent) {
percent = clampPercent(percent);
// Convert percent into a byte-like absolute position across the spine sizes.
size_t targetSize = (bookSize * static_cast<size_t>(percent)) / 100;
// Use an overflow-safe computation: (bookSize / 100) * percent + (bookSize % 100) * percent / 100
size_t targetSize =
(bookSize / 100) * static_cast<size_t>(percent) +
(bookSize % 100) * static_cast<size_t>(percent) / 100;
if (percent >= 100 && bookSize > 0) {
// Ensure the final percent lands inside the last spine item.
targetSize = bookSize - 1;