mirror of
https://github.com/espressif/openthread.git
synced 2026-07-22 20:14:07 +00:00
[message] update 'Write()' to use 'memmove()' instead of 'memcpy()' (#5462)
This change allows `CopyTo()` method to be used to copy bytes backwards within the same message (i.e., src and dest messages are the same and the dest offset is before src offset). Unit test `test_message` is updated in this commit to cover such a use. However, the `CopyTo()` implementing can still potentially overwrite the data when bytes are being copied forward within the same message. This commit adds an assert not allowing such a use and updates the method documentation mentioning this restriction.
This commit is contained in:
committed by
GitHub
parent
babb66d9c7
commit
e507e24ffb
@@ -144,7 +144,27 @@ void TestMessage(void)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify `CopyTo()` with same source and destination message and a backward copy.
|
||||
|
||||
for (uint16_t srcOffset = 0; srcOffset < kMaxSize; srcOffset++)
|
||||
{
|
||||
uint16_t bytesCopied;
|
||||
|
||||
message->Write(0, kMaxSize, writeBuffer);
|
||||
|
||||
bytesCopied = message->CopyTo(srcOffset, 0, kMaxSize, *message);
|
||||
VerifyOrQuit(bytesCopied == kMaxSize - srcOffset, "CopyTo() failed");
|
||||
|
||||
VerifyOrQuit(message->Read(0, kMaxSize, readBuffer) == kMaxSize, "Message::Read failed");
|
||||
|
||||
VerifyOrQuit(memcmp(&readBuffer[0], &writeBuffer[srcOffset], bytesCopied) == 0,
|
||||
"CopyTo() changed before srcOffset");
|
||||
VerifyOrQuit(memcmp(&readBuffer[bytesCopied], &writeBuffer[bytesCopied], kMaxSize - bytesCopied) == 0,
|
||||
"CopyTo() write error");
|
||||
}
|
||||
|
||||
message->Free();
|
||||
message2->Free();
|
||||
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user