Skip to content

check from_chars result for integer literals in script parser - #1214

Open
aysha-afrah26 wants to merge 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:script-parser-int-overflow
Open

aysha-afrah26 wants to merge 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:script-parser-int-overflow

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

The script parser turns each integer literal into an int64_t with std::from_chars but drops the result, so the one failure the tokenizer can still hand it, result_out_of_range, goes unnoticed. On overflow from_chars leaves the output untouched, which means a literal that does not fit in 64 bits is silently read as 0 instead of being reported. I ran into this with a bitmask: 0xFFFFFFFFFFFFFFFF in a script expression evaluates to 0 rather than all bits set, and 0x8000000000000000 or a long decimal like 99999999999999999999999 behave the same way. These expressions come straight from the XML (Script, preconditions, postconditions) and are compiled at tree build time through ParseScript/ValidateScript, so a tree that looks valid quietly computes with the wrong constant. The fix captures the from_chars result and raises a normal parse error when the literal is out of range, matching how the real-number branch already rejects bad input. Valid literals, including the int64 boundary values, are unchanged, and I added a regression test that fails before the change and passes after.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant