From d5e1d7f03d5c224f7188dff7e9fc71ebcaf1f6bc Mon Sep 17 00:00:00 2001 From: Kieran Kihn <114803508+kierankihn@users.noreply.github.com> Date: Mon, 17 Nov 2025 15:49:45 +0800 Subject: [PATCH] fix(game): add validation for card existence in `GameState::play` - Throw exception if card is not found in player's hand. - Ensure loop exits correctly after playing the card. --- src/game/GameState.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/game/GameState.cpp b/src/game/GameState.cpp index 5372b2c..ef35d22 100644 --- a/src/game/GameState.cpp +++ b/src/game/GameState.cpp @@ -62,9 +62,13 @@ namespace UNO::GAME { } const auto &handCardSet = this->getCurrentPlayer()->handCard->getCards(); - for (auto it = handCardSet.begin(); it != handCardSet.end(); it++) { + for (auto it = handCardSet.begin(); ; it++) { + if (it == handCardSet.end()) { + throw std::invalid_argument("Card not found in hand"); + } if (card.getType() == it->getType() && (card.getType() == CardType::WILD || card.getType() == CardType::WILDDRAWFOUR || card.getColor() == it->getColor())) { this->getCurrentPlayer()->handCard->play(it); + break; } }