From b004e91aa486096117cc09eadf6a05dfda133b35 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:06:00 -0800 Subject: [PATCH] fix segfault when bottoming card in deck view (#5508) --- cockatrice/src/game/zones/view_zone.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/game/zones/view_zone.cpp b/cockatrice/src/game/zones/view_zone.cpp index 9da4ecc39..9e311f51b 100644 --- a/cockatrice/src/game/zones/view_zone.cpp +++ b/cockatrice/src/game/zones/view_zone.cpp @@ -282,7 +282,8 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/) { if (!isReversed) { // if x is negative set it to add at end - if (x < 0) { + // if x is out-of-bounds then also set it to add at the end + if (x < 0 || x >= cards.size()) { x = cards.size(); } cards.insert(x, card); @@ -292,7 +293,8 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/) int insertionIndex = x - firstId; if (insertionIndex >= 0) { // card was put into a portion of the deck that's in the view - cards.insert(insertionIndex, card); + // qMin to prevent out-of-bounds error when bottoming a card that is already in the view + cards.insert(qMin(insertionIndex, cards.size()), card); } else { // card was put into a portion of the deck that's not in the view updateCardIds(ADD_CARD);