Skip to content

Commit a3da5fa

Browse files
committed
[REFACT] In ByteBuffer: simplified constructor
1 parent cf42205 commit a3da5fa

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

parser/ByteBuffer.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
#include "ByteBuffer.h"
22
#include <iostream>
33

4-
ByteBuffer::ByteBuffer(bufsize_t v_size, bufsize_t v_padding)
5-
: content(nullptr), contentSize(0), padding(v_padding),
6-
originalSize(0), m_refs(0)
7-
{
8-
if (v_size == 0) throw BufferException("Zero size requested");
9-
10-
this->content = allocContent(v_size, v_padding);
11-
this->contentSize = v_size;
12-
this->originalSize = v_size;
13-
}
144

155
ByteBuffer::ByteBuffer(BYTE *v_content, bufsize_t v_size, bufsize_t v_padding)
166
: content(nullptr), contentSize(0), padding(v_padding),
@@ -22,12 +12,19 @@ ByteBuffer::ByteBuffer(BYTE *v_content, bufsize_t v_size, bufsize_t v_padding)
2212
if (this->content) {
2313
this->contentSize = v_size;
2414
this->originalSize = v_size;
25-
::memcpy(this->content, v_content, v_size);
15+
if (v_content) {
16+
::memcpy(this->content, v_content, v_size);
17+
}
2618
}
2719
}
2820

21+
ByteBuffer::ByteBuffer(bufsize_t v_size, bufsize_t v_padding)
22+
: ByteBuffer(nullptr, v_size, v_padding)
23+
{
24+
}
25+
2926
ByteBuffer::ByteBuffer(AbstractByteBuffer *v_parent, offset_t v_offset, bufsize_t v_size, bufsize_t v_padding)
30-
: content(NULL), contentSize(0), padding(0),
27+
: content(nullptr), contentSize(0), padding(0),
3128
originalSize(0), m_refs(0)
3229
{
3330
if (!v_parent) throw BufferException("Cannot make subBuffer for NULL buffer!");

0 commit comments

Comments
 (0)