From 959dcc258ab3b28b94c1120cda91755eb7d746c3 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Fri, 7 Nov 2025 23:13:38 +0800 Subject: [PATCH] [child] convert `Neighbor` to `const void*` for the address comparison (#12116) When using some special configurations, the ot-cli-ftd will crash. The crash path is `MessageFramer::PrepareMacHeaders()` -> `Get().FindNeighbor()` -> `Get().Contains()`. The crash happens in the `ChildTable::Contains()`. Here is the system crash message: `kernel: traps: ot-cli-ftd[122376] trap invalid opcode ip:5640b7713b8e sp:7ffd6425c5f0 error:0 in ot-cli-ftd[313b8e,5640b7400000+426000]`. The root cause of the crash is that the CandidateParent is a 4 bytes aligned class and the Child is a 8 bytes aligned class. When converting the CandidateParent to Neighbor and then converting the Neighbor to Child, the program will crash due to the alignment issues. This commit replace the static_cast with the reinterpret_cast in ChildTable::Contains() to convert a Neighbor to a Child. --- src/core/thread/child_table.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/thread/child_table.hpp b/src/core/thread/child_table.hpp index 3a3b3e1e1..479dea932 100644 --- a/src/core/thread/child_table.hpp +++ b/src/core/thread/child_table.hpp @@ -308,7 +308,7 @@ public: */ bool Contains(const Neighbor &aNeighbor) const { - const Child *child = static_cast(&aNeighbor); + const void *child = &aNeighbor; return (mChildren <= child) && (child < GetArrayEnd(mChildren)); }