mirror of
https://github.com/espressif/openthread.git
synced 2026-08-12 13:47:47 +00:00
[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<NeighborTable>().FindNeighbor()` -> `Get<ChildTable>().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.
This commit is contained in:
@@ -308,7 +308,7 @@ public:
|
||||
*/
|
||||
bool Contains(const Neighbor &aNeighbor) const
|
||||
{
|
||||
const Child *child = static_cast<const Child *>(&aNeighbor);
|
||||
const void *child = &aNeighbor;
|
||||
|
||||
return (mChildren <= child) && (child < GetArrayEnd(mChildren));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user