Qt: fix possible crash on sorting custom columns

The sorting function must maintain a strict weak ordering, otherwise it
may result in crashes. In the case of custom columns, this was violated
when exactly one of the two rows had a non-numeric value.

Bug: 13023
Change-Id: Ie338b1cce5156eeb313dd33491ee3d3f2eaddf1c
Reviewed-on: https://code.wireshark.org/review/18406
Reviewed-by: Jim Young <jim.young.ws@gmail.com>
Petri-Dish: Jim Young <jim.young.ws@gmail.com>
Tested-by: Jim Young <jim.young.ws@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Peter Wu 2016-10-22 23:29:56 +02:00 committed by Anders Broman
parent 20e2edca57
commit 3b502c873f
1 changed files with 4 additions and 2 deletions

View File

@ -417,9 +417,11 @@ bool PacketListModel::recordLessThan(PacketListRecord *r1, PacketListRecord *r2)
if (!ok_r1 && !ok_r2) {
cmp_val = 0;
} else if (!ok_r1 || num_r1 < num_r2) {
} else if (!ok_r1 || (ok_r2 && num_r1 < num_r2)) {
// either r1 is invalid (and sort it before others) or both
// r1 and r2 are valid (sort normally)
cmp_val = -1;
} else if (!ok_r2 || num_r1 > num_r2) {
} else if (!ok_r2 || (ok_r1 && num_r1 > num_r2)) {
cmp_val = 1;
}
} else {