Skip to content

Commit

Permalink
Merge pull request #883 from zachar1a/fix#873-fw_buffer_allow_nullptr…
Browse files Browse the repository at this point in the history
…_as_input

Fix #873, allow nullptr as an input with buffer constructor with an a…
  • Loading branch information
LeStarch authored Aug 3, 2021
2 parents d06ab33 + ef7da74 commit ba57967
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Fw/Buffer/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ Buffer::Buffer(const Buffer& src) : Serializable(),
{}

Buffer::Buffer(U8* data, U32 size, U32 context) : Serializable(),
m_serialize_repr(data, size),
m_serialize_repr(),
m_bufferData(data),
m_size(size),
m_context(context)
{}
{
if(m_bufferData != NULL){
this->m_serialize_repr.setExtBuffer(m_bufferData, m_size);
}
}

Buffer& Buffer::operator=(const Buffer& src) {
// Ward against self-assignment
Expand Down
7 changes: 6 additions & 1 deletion Fw/Buffer/test/ut/TestBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ void test_basic() {
ASSERT_EQ(buffer_new.getContext(), 1234);
ASSERT_EQ(buffer, buffer_new);

// Creating empty buffer
Fw::Buffer testBuffer(nullptr,0);
ASSERT_EQ(testBuffer.getData(), nullptr);
ASSERT_EQ(testBuffer.getSize(), 0);

// Assignment operator with transitivity
Fw::Buffer buffer_assignment1, buffer_assignment2;
ASSERT_NE(buffer_assignment1.getData(), data);
Expand Down Expand Up @@ -133,4 +138,4 @@ TEST(Nominal, Serialization) {
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
}

0 comments on commit ba57967

Please sign in to comment.