Skip to content

Commit eeb575f

Browse files
committed
buffer: remove a pairs of asserts
There were 3 assert that assured that read and write data are of non-zero size. Actually there were no harm in it. More important is that in mpp code writing and reading of zero-size strings must be a valid case. So just remove asserts and add a test of ecoding/descoding of an empty string.
1 parent 3cfffe0 commit eeb575f

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/Buffer/Buffer.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,6 @@ template <size_t N, class allocator>
675675
void
676676
Buffer<N, allocator>::write(WData data)
677677
{
678-
assert(data.size != 0);
679-
680678
char *new_end = m_end + data.size;
681679
if (TNT_LIKELY(isSameBlock(m_end, new_end))) {
682680
// new_addr is still in block. just copy and advance.
@@ -1132,7 +1130,6 @@ template <bool LIGHT>
11321130
void
11331131
Buffer<N, allocator>::iterator_common<LIGHT>::write(WData data)
11341132
{
1135-
assert(data.size > 0);
11361133
size_t left_in_block = N - (uintptr_t) m_position % N;
11371134
while (TNT_UNLIKELY(data.size >= left_in_block)) {
11381135
std::memcpy(m_position, data.data, left_in_block);
@@ -1238,7 +1235,6 @@ template <bool LIGHT>
12381235
void
12391236
Buffer<N, allocator>::iterator_common<LIGHT>::read(RData data)
12401237
{
1241-
assert(data.size > 0);
12421238
/*
12431239
* The same implementation as in ::set() method buf vice versa:
12441240
* buffer and data sources are swapped.

test/EncDecTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ test_basic()
230230
mpp::encode(buf, std::integral_constant<bool, false>{});
231231
mpp::encode(buf, std::integral_constant<bool, true>{});
232232
// Strings.
233+
mpp::encode(buf, "");
233234
mpp::encode(buf, "abc");
234235
const char *bbb = "defg";
235236
mpp::encode(buf, bbb);
@@ -322,7 +323,9 @@ test_basic()
322323
fail_if(bt != true);
323324

324325
// Strings.
325-
std::string a;
326+
std::string a = "nothing";
327+
fail_unless(mpp::decode(run, a));
328+
fail_if(a != "");
326329
char b_data[10];
327330
size_t b_size = 0;
328331
auto b = tnt::make_ref_vector(b_data, b_size);

0 commit comments

Comments
 (0)