Skip to content

Commit 4d435c9

Browse files
authored
fix circular buffer pop (#33)
1 parent 5afc662 commit 4d435c9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

source/utils/circular_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class CircularBuffer {
9292

9393
private:
9494
void popInternal() {
95-
if (buf_[front_].is_destroyed_) {
95+
if (empty() || buf_[front_].is_destroyed_) {
9696
return;
9797
}
9898

test/buffer_test.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class CircularBufferTest : public testing::Test {
4242

4343
TEST_F(CircularBufferTest, Basic) {
4444
setup(3);
45+
for (auto i = 0; i < 1000; ++i) {
46+
buf_->pop();
47+
}
4548

4649
buf_->push(1);
4750
buf_->push(2);
@@ -91,6 +94,10 @@ TEST_F(CircularBufferTest, Basic) {
9194
buf_->pop();
9295

9396
evaluate(0, 2, true);
97+
98+
for (auto i = 0; i < 1000; ++i) {
99+
buf_->pop();
100+
}
94101
}
95102

96103
} // namespace cpp2sky

0 commit comments

Comments
 (0)