Skip to content

Commit

Permalink
guard against invalid games
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewprock-anari committed Nov 23, 2024
1 parent 511c1da commit f514713
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/lib/pokerstove/peval/PokerHandEvaluator.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ TEST(PokerHandEvaluator, OmahaHigh)
EXPECT_EQ(true, evaluator->usesSuits());
EXPECT_EQ(5, evaluator->boardSize());
}

TEST(PokerHandEvaluator, InvalidGame)
{
using namespace pokerstove;

std::shared_ptr<PokerHandEvaluator> evaluator = PokerHandEvaluator::alloc("x");
EXPECT_EQ(nullptr, evaluator);
}

4 changes: 3 additions & 1 deletion src/lib/pokerstove/peval/PokerHandEvaluator_Alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::shared_ptr<PokerHandEvaluator> PokerHandEvaluator::alloc (const string & in
{
string strid = input;
boost::algorithm::to_lower(strid); // modifies str
std::shared_ptr<PokerHandEvaluator> ret;
std::shared_ptr<PokerHandEvaluator> ret = nullptr;
switch (strid[0])
{
case 'h': // hold'em
Expand Down Expand Up @@ -111,6 +111,8 @@ std::shared_ptr<PokerHandEvaluator> PokerHandEvaluator::alloc (const string & in
ret.reset (new BadugiHandEvaluator);
break;

default:
return ret;
}

ret->_subclassID = strid;
Expand Down

0 comments on commit f514713

Please sign in to comment.