Skip to content

Commit 89c4437

Browse files
author
Daniele Pallastrelli
committed
Fixes daniele77#47 (assertion in History::Next() when the buffer is empty)
1 parent 276bacd commit 89c4437

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Current Version: 1.1-dirty
66

77
- Specify binding IP address in CliTelnetServer (issue #44)
88
- Fix compilation with boost v. 1.70.0 (issue #40)
9+
- Fix assertion in History::Next() when buffer is empty (issue #47)
910
- Fix compilation with older boost versions (< 1.66.0)
1011
- CMake generates cli.pc configuration file for pkg-config
1112

include/cli/history.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class History
9494
// Return the next item of the history, updating the current item.
9595
std::string Next()
9696
{
97+
if (buffer.empty())
98+
return {};
9799
if (current != 0)
98100
--current;
99101
assert(current < buffer.size());

test/test_history.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,17 @@ BOOST_AUTO_TEST_CASE(Insertion)
8989
BOOST_CHECK_EQUAL(history.Previous("foo"), "item2");
9090
}
9191

92+
BOOST_AUTO_TEST_CASE(Empty)
93+
{
94+
History history(10);
95+
96+
BOOST_CHECK_EQUAL(history.Next(), "");
97+
BOOST_CHECK_EQUAL(history.Previous(""), "");
98+
99+
History history2(10);
100+
101+
BOOST_CHECK_EQUAL(history2.Previous(""), "");
102+
BOOST_CHECK_EQUAL(history2.Next(), "");
103+
}
104+
92105
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)