mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #2327] dev_overlay: avoid float-to-int overflow UB when formatting phase_for #2333
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2333
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2327
Author: @narekshaghoyandev
Created: 11/26/2026
Status: 🔄 Open
Base:
main← Head:ubiq-dev-overlay-phase-for📝 Commits (1)
cc091cddev_overlay: avoid float-to-int overflow UB when formatting phase_for📊 Changes
2 files changed (+17 additions, -4 deletions)
View changed files
📝
runtime/src/dev_overlay.h(+8 -4)📝
runtime/test/dev_overlay_test.cpp(+9 -0)📄 Description
Fixes float-to-int overflow UB in
leonida::dev_overlay::lines()(runtime/src/dev_overlay.h):s.phase_for >= 1 ? (" for " + std::to_string(int(s.phase_for)) + " s").c_str() : ""castdoubletoint, invoking undefined behavior (float-cast-overflow) for values>= 2147483648.0or+infinityand wrapping to-2147483648.std::isfinite(s.phase_for) && s.phase_for >= 1.0and format directly withstd::snprintf(..., "now: %s for %.0f s", now[s.phase], std::floor(s.phase_for)), preserving truncation for normal values while eliminating both UB and the temporarystd::string.runtime/test/dev_overlay_test.cpp.Verification
g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic -Iruntime/src runtime/test/dev_overlay_test.cpppassedg++ -std=c++20 -fsanitize=address,undefined -Wall -Wextra -Werror -pedantic -Iruntime/src runtime/test/dev_overlay_test.cpppassedhas(text, "now: refreshing textures for 1000000000000 s"), exit 1) against unmodifiedubiq/mainpython3 -I scripts/check_no_game_data.py runtime/src/dev_overlay.h runtime/test/dev_overlay_test.cppcleanClaimed in the coordination issue as: RT-DEV-OVERLAY-PHASE-FOR-OVERFLOW (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193877669)
AI-assisted: yes (Gemini)
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.