Skip to content

fix SimpleString equality for content with embedded NUL bytes - #1230

Merged
facontidavide merged 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:simple-string-embedded-nul
Oct 10, 2026
Merged

facontidavide merged 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:simple-string-embedded-nul

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

On master, with the regression test from this branch:

gtest_simple_string.cpp:387: Failure
Value of: s1 == s2
  Actual: true
Expected: false

s1 and s2 there are "a\0b" and "a\0c": operator== and operator!= compare
with strncmp, which stops at the first NUL byte, while operator< compares the
full length with memcmp, so the same pair is reported both equal and ordered.
Content with embedded NUL bytes is not hypothetical for Any, since
ImportBlackboardFromJSON decodes a JSON \u0000 escape into a real NUL and the
scripting == / != route through SimpleString: restoring
{"a":"p\u0000X","b":"p\u0000Y"} into a tree whose only node is
<AlwaysFailure _skipIf="a == b"/> ticks to SKIPPED, so the guard skips a node over
two values that are not equal. Switching the two operators to memcmp is enough,
and the size check in front of it keeps the read in bounds.

Full ctest is 526/526 on the macOS exclusion set, and the new test covers both the
in-place and the heap representation.

strncmp stops at the first NUL byte, so two different strings of equal length that agree up to an embedded NUL compared equal, while operator< ordered the same pair with memcmp. Embedded NUL bytes reach a blackboard string through ImportBlackboardFromJSON, where a JSON escape decodes to a real NUL, and the scripting == and != operators compare through SimpleString.
@facontidavide
facontidavide merged commit d1098a6 into BehaviorTree:master Oct 10, 2026
16 checks passed
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.

2 participants