fix locale-dependent std::stod fallback in Any and SwitchNode - #1218
Open
aysha-afrah26 wants to merge 1 commit into
Open
aysha-afrah26 wants to merge 1 commit into
aysha-afrah26 wants to merge 1 commit into
Conversation
The fallback used where the floating-point std::from_chars overload is missing (Apple libc++) honors LC_NUMERIC, so under a comma-decimal locale "3.5" silently parsed as 3. Route both fallbacks through the locale-independent BT::parseDouble already used by convertFromString.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


On toolchains without the floating-point std::from_chars overload, which is the case for Apple libc++ and therefore the macOS CI job, Any::stringToNumber and the real-number comparison in CheckStringEquality fall back to std::stod. That call honors LC_NUMERIC, so as soon as the host application selects a locale that uses a comma as decimal separator (Qt and GTK programs call setlocale(LC_ALL, "") at startup) the string "3.5" comes back as 3 with the fraction silently dropped, because strtod stops at the dot and the fallback treats that as success. Every string to number conversion that goes through Any is affected: Blackboard::get on a string entry, script comparisons and assignments that mix a string variable with a number, and Switch case routing, where variable="3.50" case_1="3.5" ends up in the default child. I noticed it while reading the from_chars fallbacks after #1167 and reproduced it on macOS with a de_DE thread locale set through uselocale(). Since #1167 the library already has a locale-independent BT::parseDouble that mirrors std::from_chars, so the fix routes both remaining fallbacks through it (prefix semantics in Any, full-string in the switch comparison, exactly like their from_chars branches) instead of keeping a second parsing convention around. The only header change is a forward declaration in safe_any.hpp, because basic_types.h includes that header and not the other way round; Any::stringToNumber is an inline template and the exported signature of CheckStringEquality is unchanged, so there is no ABI impact. The two regression tests switch only the calling thread to a comma-decimal locale and skip when the machine does not have one, so they fail before and pass after on macOS and stay green on Linux and Windows, where from_chars is used.