improve LogBufferElement copy constructor

LogBufferElement copy constructor supported only partial function.

Solution: handle all cases.

Test: unit test for calling the copy constructor with all possible states.
Change-Id: I55091569d98eb35a09b4c3fc068836ecd256558c
This commit is contained in:
Jintao Zhu 2018-12-19 22:20:12 +08:00
parent b81bc9ec00
commit 245fb369b1

View file

@ -55,8 +55,19 @@ LogBufferElement::LogBufferElement(const LogBufferElement& elem)
mMsgLen(elem.mMsgLen),
mLogId(elem.mLogId),
mDropped(elem.mDropped) {
mMsg = new char[mMsgLen];
memcpy(mMsg, elem.mMsg, mMsgLen);
if (mDropped) {
if (elem.isBinary() && elem.mMsg != nullptr) {
// for the following "len" value, refer to : setDropped(uint16_t value), getTag()
const int len = sizeof(android_event_header_t);
mMsg = new char[len];
memcpy(mMsg, elem.mMsg, len);
} else {
mMsg = nullptr;
}
} else {
mMsg = new char[mMsgLen];
memcpy(mMsg, elem.mMsg, mMsgLen);
}
}
LogBufferElement::~LogBufferElement() {