Skip to content

fix(ini): Preserve legacy parsing for out-of-range numbers - #3436

Open
CryoTheRenegade wants to merge 6 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:fix/2804-ini-overflow-fallback
Open

CryoTheRenegade wants to merge 6 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:fix/2804-ini-overflow-fallback

Conversation

@CryoTheRenegade

@CryoTheRenegade CryoTheRenegade commented Oct 8, 2026 •

Copy link
Copy Markdown

Fixes #2804

ShockWave uses SpawnReplaceDelay = 9999999999999999999, which exceeds the signed 64-bit range used by the std::from_chars parser and causes a startup crash.

When std::from_chars reports result_out_of_range, retry with strtoll, strtoull, or strtof. Integer conversion preserves the tested Windows legacy saturation and narrowing behavior. Floating-point overflow and underflow now produce legacy infinity or signed-zero results instead of a parse error.

Accept a null-terminated const char* token for the fallback and use a string_view internally for from_chars. Skip a leading + only for from_chars, but reject a following minus sign before parsing. This restores legacy rejection of double-sign inputs such as +-99999999 and +-1.25 on both the fast and fallback paths.

AI assistance: Codex assisted with implementation, generated the tests, and ran the automated checks and earlier game smoke test.

Parser benchmark

ClangCL 23.1.3, Win32 Release, Intel Core i5-14500, Windows 11 Pro. Five randomly interleaved repetitions, 0.2 seconds minimum CPU time per repetition. Median CPU time divided by four tokens per iteration. Measured on 2026-10-12 with the benchmark added in d32299911.

Zero Hour

Input Current ns/token sscanf ns/token sscanf/current
Int ordinary 7.85 54.69 6.97x
Int overflow 78.47 111.17 1.42x
UnsignedInt ordinary 7.41 55.47 7.48x
UnsignedInt overflow 91.55 104.63 1.14x
Real ordinary 31.39 113.35 3.61x
Real overflow 91.55 95.91 1.05x
Real underflow 209.26 165.67 0.79x

Generals

Input Current ns/token sscanf ns/token sscanf/current
Int ordinary 6.98 50.78 7.28x
Int overflow 104.63 111.17 1.06x
UnsignedInt ordinary 7.85 56.68 7.22x
UnsignedInt overflow 91.55 111.17 1.21x
Real ordinary 33.35 104.63 3.14x
Real overflow 95.91 95.91 1.00x
Real underflow 217.98 165.67 0.76x

Each case uses four fixed tokens, not a measured distribution of game INI inputs. The current side calls the production INI scanners. The legacy side uses the original sscanf conversion and failure check. Results are local microbenchmarks, not game startup timings. Out-of-range sscanf results characterize this Windows CRT and are not portable C behavior.

Each game was measured separately using default OS scheduling, without processor affinity. Small timing differences should not be treated as conclusive speedups. Reproduction commands are in TESTING.md.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ef4c2768-ab89-4dee-9d83-41bd733fea22
📥 Commits

Reviewing files that changed from the base of the PR and between 07c96c5 and bccdef8.

📒 Files selected for processing (2)
  • Core/GameEngine/Source/Common/INI/INI.cpp
  • Tests/Google/Core/GameEngine/Common/INITest.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • Core/GameEngine/Source/Common/INI/INI.cpp
  • Tests/Google/Core/GameEngine/Common/INITest.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

Integral INI parsing now retries out-of-range std::from_chars results with strtoll or strtoull. New tests cover oversized and invalid integers, real-number overflow, and registration in the Google Test build.

Changes

INI Parsing

Layer / File(s) Summary
Out-of-range integer parsing
Core/GameEngine/Source/Common/INI/INI.cpp
scanType accepts the original C-string token and constructs a std::string_view internally. For out-of-range integral values, it retries with strtoll or strtoull based on signedness. It throws INI_INVALID_DATA if no characters were converted.
Scanner tests and test registration
Tests/Google/Core/GameEngine/Common/INITest.cpp, Tests/Google/Core/CMakeLists.txt
New tests check oversized integer results, invalid integer tokens, and real-number overflow. CMake adds the test source to the Google Test target.

Priority: ⬆️ High

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: caball009

Merge Risk: ⚪ Minimal · up to bccde

The change addresses the reported oversized INI value, and no actionable merge-blocking issue remains after normal checks.

Pre-merge checks · Passed 4
Passed Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Issue #2804 requires the oversized SpawnReplaceDelay value to avoid the C++17 INI parsing failure. INI.cpp now handles std::from_chars result_out_of_range for integral values with strtoll or…
Out of Scope Changes check Passed The changes are limited to integer fallback parsing, focused INI parser tests, and test-target registration. Each change supports issue #2804. No unrelated change is shown.
Title check Passed The title clearly summarizes the main change: preserving legacy parsing for out-of-range INI numbers.
Description check Passed The description directly explains the parsing failure, fallback behavior, compatibility requirements, tests, and benchmark results.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR restores legacy results for numbers outside the parser’s range and rejects double-sign inputs.

  • INI numbers keep their legacy results when they exceed parser limits.
  • INI benchmarks compare current numeric scans with the old sscanf conversion.

Reviews (9) · Last reviewed commit: "perf(ini): Add numeric parser benchmarks..." · Reviewed by Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c3e0abfb-a13f-4e06-b88e-52951e0256b0
📥 Commits

Reviewing files that changed from the base of the PR and between adac468 and 5f26b42.

📒 Files selected for processing (3)
  • Core/GameEngine/Source/Common/INI/INI.cpp
  • Tests/Google/Core/CMakeLists.txt
  • Tests/Google/Core/GameEngine/Common/INITest.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread Core/GameEngine/Source/Common/INI/INI.cpp Outdated
Comment thread Tests/Google/Core/GameEngine/Common/INITest.cpp Outdated

@Skyaero42 Skyaero42 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR feels very AI-ish without human oversight.

Comment thread Core/GameEngine/Source/Common/INI/INI.cpp
Comment thread Core/GameEngine/Source/Common/INI/INI.cpp Outdated
Comment thread Core/GameEngine/Source/Common/INI/INI.cpp Outdated
Comment thread Tests/Google/Core/GameEngine/Common/INITest.cpp
Comment thread Core/GameEngine/Source/Common/INI/INI.cpp Outdated
@CryoTheRenegade CryoTheRenegade changed the title fix(ini): Preserve legacy parsing for oversized integers fix(ini): Preserve legacy parsing for out-of-range numbers Oct 10, 2026

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a bit complicated, but if this is faster and gives same results as original, then ok.

Comment thread Core/GameEngine/Source/Common/INI/INI.cpp Outdated
Comment thread Core/GameEngine/Source/Common/INI/INI.cpp Outdated
Comment thread Core/GameEngine/Source/Common/INI/INI.cpp
Comment thread Tests/Google/Core/GameEngine/Common/INITest.cpp
Comment thread Benchmarks/Google/Core/GameEngine/Common/INIBenchmark.cpp
@CryoTheRenegade
CryoTheRenegade force-pushed the fix/2804-ini-overflow-fallback branch from 58fd63c to f5f6dfa Compare October 10, 2026 21:03

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. If it works it works. You can also generate a benchmark for it.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker ThisProject The issue was introduced by this project, or this task is specific to this project System Is Systems related Fix Is fixing something, but is not user facing Mod Relates to Mods or modding labels Oct 11, 2026

@Caball009 Caball009 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok.

Good to see better support for legacy parsing.

@xezon

xezon commented Oct 12, 2026

Copy link
Copy Markdown

Benchmarks still coming or not?

@CryoTheRenegade
CryoTheRenegade force-pushed the fix/2804-ini-overflow-fallback branch from f5f6dfa to 4f68d8f Compare October 12, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Minor Severity: Minor < Major < Critical < Blocker Mod Relates to Mods or modding System Is Systems related ThisProject The issue was introduced by this project, or this task is specific to this project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

INI parsing with std::from_chars throws exception for value that is out of range

4 participants