fix(ini): Support plus sign character prefix in INI integer parse#2576
fix(ini): Support plus sign character prefix in INI integer parse#2576xezon wants to merge 3 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/Common/INI/INI.cpp | Strips leading + sign before std::from_chars parsing and corrects the intermediate result type from Real to the template parameter Type; logic is sound and edge cases are all handled correctly or intentionally acknowledged. |
Reviews (3): Last reviewed commit: "tweak assert message" | Re-trigger Greptile
| std::conditional_t<std::is_integral_v<Type>, Int64, Real> result{}; | ||
| DEBUG_ASSERTCRASH(!token.empty(), ("token is not expected empty")); | ||
|
|
||
| // Unlike sscanf, std::from_chars cannot parse "+" |
There was a problem hiding this comment.
Same as #2548, this 'fix' needs a comment on why we want to keep parsing the '+' sign
// TheSuperHackers @info std::from_chars does not support a leading '+' sign. Strip it to match // sscanf and accommodate mod makers who use explicit signed values (e.g. +20 / -20).
There was a problem hiding this comment.
I do not think this level of detail is required for this comment. The comment already clarifies that from_chars behaves different to sscanf, and this difference is mitigated accordingly.
There was a problem hiding this comment.
Could add to the first post that this change is not required for the default ini files.
There was a problem hiding this comment.
Ok did that. It is implicitly mentioned by the "Mod" label as well.
| { | ||
| // TheSuperHackers @info std::from_chars cannot parse "-1" as uint32 so the result needs to be int64 for integers. | ||
| std::conditional_t<std::is_integral_v<Type>, Int64, Real> result{}; | ||
| DEBUG_ASSERTCRASH(!token.empty(), ("token is not expected empty")); |
There was a problem hiding this comment.
nit: "token is not expected to be empty"
| DEBUG_ASSERTCRASH(!token.empty(), ("token is not expected empty")); | ||
|
|
||
| // Unlike sscanf, std::from_chars cannot parse "+" | ||
| if (token[0] == '+') |
There was a problem hiding this comment.
Do we care about "+" for integers? If we only care about "+" for floating point values, we could do something like:
if constexpr (std::floating_point<Type>)
{
// Unlike sscanf, std::from_chars cannot parse "+"
if (token[0] == '+')
{
token.remove_prefix(1);
}
}There was a problem hiding this comment.
In INI file, integer and float are indistinguishable, so a user could add + to both and not be aware about its underlying type.
What's this based on? Did you check all call sites? |
I launched the game and it did not hit the assert condition. |
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.