cabana: fix segfault on descending sort (#26995)

old-commit-hash: ef89ec3eb0
beeps
Willem Melching 2 years ago committed by GitHub
parent 5a74a8db6d
commit 7ad0b07b7b
  1. 15
      tools/cabana/messageswidget.cc

@ -96,8 +96,9 @@ void MessageListModel::sortMessages() {
beginResetModel(); beginResetModel();
if (sort_column == 0) { if (sort_column == 0) {
std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) { std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) {
bool ret = std::pair{msgName(l), l} < std::pair{msgName(r), r}; auto ll = std::pair{msgName(l), l};
return sort_order == Qt::AscendingOrder ? ret : !ret; auto rr = std::pair{msgName(r), r};
return sort_order == Qt::AscendingOrder ? ll < rr : ll > rr;
}); });
} else if (sort_column == 1) { } else if (sort_column == 1) {
std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) { std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) {
@ -105,13 +106,15 @@ void MessageListModel::sortMessages() {
}); });
} else if (sort_column == 2) { } else if (sort_column == 2) {
std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) { std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) {
bool ret = std::pair{can->lastMessage(l).freq, l} < std::pair{can->lastMessage(r).freq, r}; auto ll = std::pair{can->lastMessage(l).freq, l};
return sort_order == Qt::AscendingOrder ? ret : !ret; auto rr = std::pair{can->lastMessage(r).freq, r};
return sort_order == Qt::AscendingOrder ? ll < rr : ll > rr;
}); });
} else if (sort_column == 3) { } else if (sort_column == 3) {
std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) { std::sort(msgs.begin(), msgs.end(), [this](auto &l, auto &r) {
bool ret = std::pair{can->lastMessage(l).count, l} < std::pair{can->lastMessage(r).count, r}; auto ll = std::pair{can->lastMessage(l).count, l};
return sort_order == Qt::AscendingOrder ? ret : !ret; auto rr = std::pair{can->lastMessage(r).count, r};
return sort_order == Qt::AscendingOrder ? ll < rr : ll > rr;
}); });
} }
endResetModel(); endResetModel();

Loading…
Cancel
Save