diff options
| author | Méven Car <[email protected]> | 2026-06-25 19:08:18 +0000 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2026-06-25 21:09:01 +0200 |
| commit | 50c8b5a3eefcb95c4c0a07c454311ad650f0b5ae (patch) | |
| tree | 95342364fc647a6d7d70cea86d6a607c1fad3150 | |
| parent | 4ef472552712b476d567823e6b1796b032acae9a (diff) | |
kfileitemmodel: Avoid zero-as-null-pointer-constant warnings in natural sort
The natural sort comparison helpers compare Qt::strong_ordering values
against the literal 0. The compiler reads that 0 as a null pointer
constant and warns under -Wzero-as-null-pointer-constant.
Use the named ordering helpers is_lt, is_gt and is_neq instead, which
express the same checks without a literal 0. The plain integer
comparisons in the surrounding code are left as they are.
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index f4b51ce72..549217761 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -61,11 +61,11 @@ Qt::strong_ordering orderingFromInt(int result) int orderingToInt(Qt::strong_ordering ordering) { - if (ordering < 0) { + if (is_lt(ordering)) { return -1; } - if (ordering > 0) { + if (is_gt(ordering)) { return 1; } @@ -149,7 +149,7 @@ Qt::strong_ordering compareNumericChains(const QString &a, int startA, int endA, const int dotB = findDigitRunEnd(b, startB); const Qt::strong_ordering integerResult = compareDigitStrings(a.mid(startA, dotA - startA), b.mid(startB, dotB - startB)); - if (integerResult != 0) { + if (is_neq(integerResult)) { return integerResult; } @@ -165,7 +165,7 @@ Qt::strong_ordering compareNumericChains(const QString &a, int startA, int endA, const Qt::strong_ordering segmentResult = compareDigitStrings(a.mid(segmentStartA, segmentEndA - segmentStartA), b.mid(segmentStartB, segmentEndB - segmentStartB)); - if (segmentResult != 0) { + if (is_neq(segmentResult)) { return segmentResult; } @@ -218,7 +218,7 @@ Qt::strong_ordering decimalAwareNaturalCompare(const QString &a, const QString & const Qt::strong_ordering numericResult = compareNumericChains(a, indexA, chainEndA, segmentCountA, b, indexB, chainEndB, segmentCountB); indexA = chainEndA; indexB = chainEndB; - if (numericResult != 0) { + if (is_neq(numericResult)) { return numericResult; } @@ -236,7 +236,7 @@ Qt::strong_ordering decimalAwareNaturalCompare(const QString &a, const QString & } const Qt::strong_ordering textResult = orderingFromInt(collator.compare(a.mid(indexA, textEndA - indexA), b.mid(indexB, textEndB - indexB))); - if (textResult != 0) { + if (is_neq(textResult)) { return orderingFromInt(collator.compare(a.mid(indexA), b.mid(indexB))); } @@ -245,7 +245,7 @@ Qt::strong_ordering decimalAwareNaturalCompare(const QString &a, const QString & } const Qt::strong_ordering remainderResult = orderingFromInt(collator.compare(a.mid(indexA), b.mid(indexB))); - if (remainderResult != 0) { + if (is_neq(remainderResult)) { return remainderResult; } @@ -254,7 +254,7 @@ Qt::strong_ordering decimalAwareNaturalCompare(const QString &a, const QString & } const Qt::strong_ordering result = orderingFromInt(QString::compare(a, b, collator.caseSensitivity())); - if (result != 0 || collator.caseSensitivity() == Qt::CaseSensitive) { + if (is_neq(result) || collator.caseSensitivity() == Qt::CaseSensitive) { return result; } |
