Skip to content

Commit f65951d

Browse files
committed
Buffer: fix assertion
By a mistake a debug assertion was placed in a bit wrong place. Move it to the right position. Add a test. Part of #28
1 parent 6a2362b commit f65951d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Buffer/Buffer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,17 +787,17 @@ Buffer<N, allocator>::dropBack(size_t size)
787787

788788
/* Do not delete the block if it is empty after drop. */
789789
while (TNT_UNLIKELY(size > left_in_block)) {
790-
assert(!m_blocks.isEmpty());
791-
delBlock(block);
792-
block = &m_blocks.last();
793-
794790
/*
795791
* Make sure there's no iterators pointing to the block
796792
* to be dropped.
797793
*/
798794
assert(m_iterators.isEmpty() ||
799795
m_iterators.last().getBlock() != block);
800796

797+
assert(!m_blocks.isEmpty());
798+
delBlock(block);
799+
block = &m_blocks.last();
800+
801801
m_end = block->end();
802802
size -= left_in_block;
803803
left_in_block = Block::DATA_SIZE;

test/BufferUnitTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ buffer_basic()
214214
buf2.dropBack(i);
215215
fail_unless(*buf2.begin() == c);
216216
}
217+
218+
// Check when there a heavy iterators.
219+
for (size_t i = 0; i < N; i++) {
220+
tnt::Buffer<N> buf2;
221+
if (i != 0)
222+
buf2.write({i});
223+
itr = buf2.end();
224+
for (size_t j = 1; j < N; j++) {
225+
buf2.write({j});
226+
buf2.dropBack(j);
227+
}
228+
fail_unless(buf2.end() == itr);
229+
}
217230
}
218231

219232
/**

0 commit comments

Comments
 (0)