Skip to content

Commit

Permalink
Fix #873, allow nullptr as an input with buffer constructor with an a…
Browse files Browse the repository at this point in the history
…ccompanying test
  • Loading branch information
zachar1a committed Aug 2, 2021
1 parent d589f0a commit 0cf94cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Fw/Buffer/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ Buffer::Buffer(const Buffer& src) : Serializable(),
{}

Buffer::Buffer(U8* data, U32 size, U32 context) : Serializable(),
#if data == nullptr && size == 0
m_serialize_repr(),
m_bufferData(NULL),
m_size(0),
m_context(0xFFFFFFFF)
{}
#else
m_serialize_repr(data, size),
m_bufferData(data),
m_size(size),
m_context(context)
{}
{}
#endif

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 0cf94cd

Please sign in to comment.