Skip to content

fix(ini): Support plus sign character prefix in INI integer parse#2576

Open
xezon wants to merge 4 commits intoTheSuperHackers:mainfrom
xezon:xezon/fix-ini-scanint
Open

fix(ini): Support plus sign character prefix in INI integer parse#2576
xezon wants to merge 4 commits intoTheSuperHackers:mainfrom
xezon:xezon/fix-ini-scanint

Conversation

@xezon
Copy link
Copy Markdown

@xezon xezon commented Apr 11, 2026

Alternative fix to #2548

Omits empty test because a token is implicitly not empty.

This change was not required for the original INI files.

Tested and worked.

@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 Fix Is fixing something, but is not user facing Mod Relates to Mods or modding labels Apr 11, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 11, 2026

Greptile Summary

This PR adds support for parsing INI integer values prefixed with a + sign when using the std::from_chars code path (USE_STD_FROM_CHARS_PARSING), since from_chars — unlike sscanf — does not accept a leading +. It also corrects the intermediate result type from the hardcoded Real to the template parameter Type for non-integral types, which is functionally equivalent today (since Real = float) but more accurately generic.

Confidence Score: 5/5

Safe to merge — the change is minimal, correct, and consistent with the existing sscanf behaviour.

No P0 or P1 findings. The + stripping is guarded by the pre-existing token-non-empty contract (enforced by the new debug assert), remove_prefix(1) is safe because the [0] check already implies size ≥ 1, and the Real → Type substitution is functionally identical for all current call sites.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngine/Source/Common/INI/INI.cpp Adds leading + stripping and a debug assertion to scanType<>, and generalises the non-integral result type from Real to Type — all changes are correct and safe.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["scanType(token)"] --> B{"token empty?"}
    B -->|"debug assert"| B2["DEBUG_ASSERTCRASH"]
    B -->|"not empty"| C{"token[0] == plus?"}
    C -->|"yes"| D["token.remove_prefix(1)"]
    C -->|"no"| E["from_chars(token, result)"]
    D --> E
    E --> F{"ec == errc{}?"}
    F -->|"error"| G["throw INI_INVALID_DATA"]
    F -->|"success"| H["return static_cast(result)"]
Loading

Reviews (4): Last reviewed commit: "Add extra comment" | Re-trigger Greptile

@Caball009
Copy link
Copy Markdown

Omits empty test because a token is implicitly not empty.

What's this based on? Did you check all call sites?

@xezon
Copy link
Copy Markdown
Author

xezon commented Apr 12, 2026

What's this based on? Did you check all call sites?

I launched the game and it did not hit the assert condition.

Copy link
Copy Markdown

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

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

Thank you. looks good now

@Caball009
Copy link
Copy Markdown

Caball009 commented Apr 12, 2026

What's this based on? Did you check all call sites?

I launched the game and it did not hit the assert condition.

This PR exists because I did the same thing in the previous PR, and that wasn't enough because I only tested the standard INI files.

I just checked all call sites, though, and it looks safe.

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 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.

3 participants