diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 9fe3e6e..999d758 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -452,7 +452,7 @@ QString GameState::generateStateHash() const { stateHash += ","; } - if (stateHash.last(1) != "|") + if (stateHash.length() > 0 && stateHash.last(1) != "|") stateHash.removeLast(); stateHash += "|"; } @@ -464,7 +464,7 @@ QString GameState::generateStateHash() const { for (const PlayingCard* card : foundationPile) { stateHash += QString::number(card->value()) + "." + QString::number(card->suit()) + ","; } - if (stateHash.last(1) != "|") + if (stateHash.length() > 0 && stateHash.last(1) != "|") stateHash.removeLast(); stateHash += "|"; } @@ -588,7 +588,8 @@ bool GameState::isColumnMoveValid(const PlayingCard& cardToMove, int columnId) c const PlayingCard& columnCard = *columnStack.last()->card(); // The card's value must be one less than the card in the column - if (cardToMove.value() != static_cast(static_cast(columnCard.value() - 1))) + const int reqValue = static_cast(columnCard.value() - 1); + if (reqValue < 0 || cardToMove.value() != static_cast(reqValue)) return false; // The card must be of opposite color