Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 245fb369 authored by Jintao Zhu's avatar Jintao Zhu
Browse files

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
parent b81bc9ec
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -55,9 +55,20 @@ LogBufferElement::LogBufferElement(const LogBufferElement& elem)
      mMsgLen(elem.mMsgLen),
      mLogId(elem.mLogId),
      mDropped(elem.mDropped) {
    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() {
    delete[] mMsg;