Skip to content

Commit f514713

Browse files
guard against invalid games
1 parent 511c1da commit f514713

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/lib/pokerstove/peval/PokerHandEvaluator.test.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ TEST(PokerHandEvaluator, OmahaHigh)
99
EXPECT_EQ(true, evaluator->usesSuits());
1010
EXPECT_EQ(5, evaluator->boardSize());
1111
}
12+
13+
TEST(PokerHandEvaluator, InvalidGame)
14+
{
15+
using namespace pokerstove;
16+
17+
std::shared_ptr<PokerHandEvaluator> evaluator = PokerHandEvaluator::alloc("x");
18+
EXPECT_EQ(nullptr, evaluator);
19+
}
20+

src/lib/pokerstove/peval/PokerHandEvaluator_Alloc.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ std::shared_ptr<PokerHandEvaluator> PokerHandEvaluator::alloc (const string & in
2626
{
2727
string strid = input;
2828
boost::algorithm::to_lower(strid); // modifies str
29-
std::shared_ptr<PokerHandEvaluator> ret;
29+
std::shared_ptr<PokerHandEvaluator> ret = nullptr;
3030
switch (strid[0])
3131
{
3232
case 'h': // hold'em
@@ -111,6 +111,8 @@ std::shared_ptr<PokerHandEvaluator> PokerHandEvaluator::alloc (const string & in
111111
ret.reset (new BadugiHandEvaluator);
112112
break;
113113

114+
default:
115+
return ret;
114116
}
115117

116118
ret->_subclassID = strid;

0 commit comments

Comments
 (0)