dev_overlay: avoid float-to-int overflow UB when formatting phase_for #2327
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2327
Loading…
Reference in a new issue
No description provided.
Delete branch "ubiq-dev-overlay-phase-for"
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 successfully merged and closed
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)
VERIFY-2327— verified headcc091cd4ccmerged cleanly withmaind48a957bbon Windows 11 Pro (build 26200), MSVC19.44(x64,/std:c++20 /W4 /WX /permissive- /utf-8 /EHsc), synthetic overlay samples only.Red (
maind48a957bb) -> Green (d48a957bb+cc091cd4cc)main:runtime/test/dev_overlay_test.cppagainstmain'sruntime/src/dev_overlay.h-> FAILED (exit 1atline 168: has(text, "now: refreshing textures for 1000000000000 s")due toint(s.phase_for)float-to-int overflow on1e12).cl.exe /nologo /std:c++20 /W4 /WX /permissive- /utf-8 /EHsc /I"runtime/src" runtime/test/dev_overlay_test.cpp-> 0 warnings, exit0(dev_overlay_test: ok).AI-assisted.
Red/green: On main dev_overlay_test fails at line 168 (a huge phase duration overflows the float-to-int conversion and prints 1000000000000 s), and with the PR ctest -R "^dev_overlay$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
Verified by OreoFR
c1ecf04ed+ PR headcc091cd4c; green run in a merge package of 16 PRs, no new ctest failure vs mainctest -R "^dev_overlay$"AI-assisted (Claude Code, Claude Opus 5.5).