Skip to content

Commit

Permalink
Fixes #47 (assertion in History::Next() when the buffer is empty)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Pallastrelli committed Jul 22, 2019
1 parent 276bacd commit 89c4437
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Current Version: 1.1-dirty

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

Expand Down
2 changes: 2 additions & 0 deletions include/cli/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class History
// Return the next item of the history, updating the current item.
std::string Next()
{
if (buffer.empty())
return {};
if (current != 0)
--current;
assert(current < buffer.size());
Expand Down
13 changes: 13 additions & 0 deletions test/test_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,17 @@ BOOST_AUTO_TEST_CASE(Insertion)
BOOST_CHECK_EQUAL(history.Previous("foo"), "item2");
}

BOOST_AUTO_TEST_CASE(Empty)
{
History history(10);

BOOST_CHECK_EQUAL(history.Next(), "");
BOOST_CHECK_EQUAL(history.Previous(""), "");

History history2(10);

BOOST_CHECK_EQUAL(history2.Previous(""), "");
BOOST_CHECK_EQUAL(history2.Next(), "");
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 89c4437

Please sign in to comment.