From f5147133d573d1f0d2287ca2486d17056a6f87eb Mon Sep 17 00:00:00 2001 From: Andrew Prock Date: Sat, 23 Nov 2024 11:45:21 -0800 Subject: [PATCH] guard against invalid games --- src/lib/pokerstove/peval/PokerHandEvaluator.test.cpp | 9 +++++++++ src/lib/pokerstove/peval/PokerHandEvaluator_Alloc.cpp | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/pokerstove/peval/PokerHandEvaluator.test.cpp b/src/lib/pokerstove/peval/PokerHandEvaluator.test.cpp index ba6fcf4..3b39a1d 100644 --- a/src/lib/pokerstove/peval/PokerHandEvaluator.test.cpp +++ b/src/lib/pokerstove/peval/PokerHandEvaluator.test.cpp @@ -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 evaluator = PokerHandEvaluator::alloc("x"); + EXPECT_EQ(nullptr, evaluator); +} + diff --git a/src/lib/pokerstove/peval/PokerHandEvaluator_Alloc.cpp b/src/lib/pokerstove/peval/PokerHandEvaluator_Alloc.cpp index 87c005c..d20922a 100644 --- a/src/lib/pokerstove/peval/PokerHandEvaluator_Alloc.cpp +++ b/src/lib/pokerstove/peval/PokerHandEvaluator_Alloc.cpp @@ -26,7 +26,7 @@ std::shared_ptr PokerHandEvaluator::alloc (const string & in { string strid = input; boost::algorithm::to_lower(strid); // modifies str - std::shared_ptr ret; + std::shared_ptr ret = nullptr; switch (strid[0]) { case 'h': // hold'em @@ -111,6 +111,8 @@ std::shared_ptr PokerHandEvaluator::alloc (const string & in ret.reset (new BadugiHandEvaluator); break; + default: + return ret; } ret->_subclassID = strid;