mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-30 18:43:55 -07:00
Fix StackZone crash when divideCardSpaceInZone overflows (#5751)
The divideCardSpaceInZone function introduced in #4930 is buggy and sometimes returns an index that is too large for the current zone, which causes us to call `cards.at(index)` with an `index` that's bigger than the amount of cards. This is the bug that #5609 intended to fix but was improperly diagnosed. Remove part of #5609 as the cases it is guarding against (e.g. null card pointer) cannot actually happen.
This commit is contained in:
parent
2e01dfd23a
commit
76fa87c63e
3 changed files with 14 additions and 19 deletions
|
|
@ -47,8 +47,6 @@
|
||||||
# card_info = false
|
# card_info = false
|
||||||
# card_list = false
|
# card_list = false
|
||||||
|
|
||||||
# stack_zone = false
|
|
||||||
|
|
||||||
flow_layout.debug = false
|
flow_layout.debug = false
|
||||||
flow_widget.debug = false
|
flow_widget.debug = false
|
||||||
flow_widget.size.debug = false
|
flow_widget.size.debug = false
|
||||||
|
|
|
||||||
|
|
@ -66,26 +66,25 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone
|
||||||
cmd.set_target_zone(getName().toStdString());
|
cmd.set_target_zone(getName().toStdString());
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
if (cards.isEmpty()) {
|
|
||||||
index = 0;
|
if (!cards.isEmpty()) {
|
||||||
} else {
|
|
||||||
const auto cardCount = static_cast<int>(cards.size());
|
const auto cardCount = static_cast<int>(cards.size());
|
||||||
const auto &card = cards.at(0);
|
const auto &card = cards.at(0);
|
||||||
|
|
||||||
if (card == nullptr) {
|
|
||||||
qCWarning(StackZoneLog) << "Attempted to move card from" << startZone->getName() << ", but was null";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
index = qRound(divideCardSpaceInZone(dropPoint.y(), cardCount, boundingRect().height(),
|
index = qRound(divideCardSpaceInZone(dropPoint.y(), cardCount, boundingRect().height(),
|
||||||
card->boundingRect().height(), true));
|
card->boundingRect().height(), true));
|
||||||
}
|
|
||||||
|
|
||||||
if (startZone == this) {
|
// divideCardSpaceInZone is not guaranteed to return a valid index
|
||||||
const auto &dragItem = dragItems.at(0);
|
// currently, so clamp it to avoid crashes.
|
||||||
const auto &card = cards.at(index);
|
index = qBound(0, index, cardCount - 1);
|
||||||
if (card != nullptr && dragItem != nullptr && card->getId() == dragItem->getId()) {
|
|
||||||
return;
|
if (startZone == this) {
|
||||||
|
const auto &dragItem = dragItems.at(0);
|
||||||
|
const auto &card = cards.at(index);
|
||||||
|
|
||||||
|
if (card->getId() == dragItem->getId()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
#include "select_zone.h"
|
#include "select_zone.h"
|
||||||
|
|
||||||
inline Q_LOGGING_CATEGORY(StackZoneLog, "stack_zone");
|
|
||||||
|
|
||||||
class StackZone : public SelectZone
|
class StackZone : public SelectZone
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue