Fix #934: segfault when substituting a SubTree node by facontidavide · Pull Request #1083 · BehaviorTree/BehaviorTree.CPP · GitHub
Skip to content

Fix #934: segfault when substituting a SubTree node#1083

Merged
facontidavide merged 2 commits into
masterfrom
fix/934-subtree-substitution-segfault
Feb 1, 2026
Merged

Fix #934: segfault when substituting a SubTree node#1083
facontidavide merged 2 commits into
masterfrom
fix/934-subtree-substitution-segfault

Conversation

@facontidavide

Copy link
Copy Markdown
Collaborator

Summary

  • Adds null-check after dynamic_cast<SubTreeNode*> in XMLParser::PImpl::recursivelyCreateTree before calling setSubtreeID
  • When a SubTree node is substituted (e.g., with a test node), the replacement is not a SubTreeNode, so the cast returns nullptr causing a segfault

Fixes #934

Test plan

  • Added Substitution.SubTreeNodeSubstitution test that reproduces the segfault by substituting a SubTree node
  • All 309 tests pass (308 existing + 1 new)

🤖 Generated with Claude Code

When a substitution rule replaced a SubTree with a TestNode,
dynamic_cast<SubTreeNode*> returned nullptr but setSubtreeID was
called unconditionally, causing a null pointer dereference. Add a
null-check so setSubtreeID is only called on actual SubTree nodes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Feb 1, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Feb 1, 2026

Copy link
Copy Markdown

Use explicit != nullptr comparisons for pointer-to-bool conversions
flagged by clang-tidy.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@facontidavide facontidavide marked this pull request as ready for review February 1, 2026 19:39
@facontidavide facontidavide merged commit 25407ad into master Feb 1, 2026
13 checks passed
@facontidavide facontidavide deleted the fix/934-subtree-substitution-segfault branch February 1, 2026 19:39
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.

Segmentation fault when substituting subtree

1 participant