Author: Lars Knoll <lars.knoll@digia.com>
Date: Fri, 5 Sep 2014 12:58:19 +0200
Description: [PATCH] Fix bugs in internal comparison operators
Lisandro removed the tests part as it didn't apply and we are not
running them anyway.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The comparison operators between QJsonPrivate::String
and QJsonPrivate::Latin1String weren't all correct, leading
to wrong sorting of keys in QJsonObjects when the keys were
outside of the latin1 range and resulting lookup errors.
Task-number: QTBUG-41100
Change-Id: Idceff615f85d7ab874ad2a8e4a6c1ce8c2aa0f65
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
---
src/corelib/json/qjson_p.h | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
|
|
|
352 | 352 | return !memcmp(d->utf16, str.d->utf16, d->length*sizeof(ushort)); |
353 | 353 | } |
354 | 354 | inline bool operator<(const String &other) const; |
355 | | inline bool operator >=(const String &other) const { return other < *this; } |
| 355 | inline bool operator >=(const String &other) const { return !(*this < other); } |
356 | 356 | |
357 | 357 | inline QString toString() const { |
358 | 358 | #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN |
… |
… |
|
412 | 412 | val = d->length - str.d->length; |
413 | 413 | return val >= 0; |
414 | 414 | } |
| 415 | inline bool operator<(const String &str) const |
| 416 | { |
| 417 | const qle_ushort *uc = (qle_ushort *) str.d->utf16; |
| 418 | if (!uc || *uc == 0) |
| 419 | return false; |
| 420 | |
| 421 | const uchar *c = (uchar *)d->latin1; |
| 422 | const uchar *e = c + qMin((int)d->length, (int)str.d->length); |
415 | 423 | |
| 424 | while (c < e) { |
| 425 | if (*c != *uc) |
| 426 | break; |
| 427 | ++c; |
| 428 | ++uc; |
| 429 | } |
| 430 | return (c == e ? (int)d->length < (int)str.d->length : *c < *uc); |
| 431 | |
| 432 | } |
416 | 433 | inline bool operator ==(const String &str) const { |
417 | 434 | return (str == *this); |
418 | 435 | } |
419 | 436 | inline bool operator >=(const String &str) const { |
420 | | return (str < *this); |
| 437 | return !(*this < str); |
421 | 438 | } |
422 | 439 | |
423 | 440 | inline QString toString() const { |
… |
… |
|
454 | 471 | a++,b++; |
455 | 472 | if (l==-1) |
456 | 473 | return (alen < blen); |
457 | | return (ushort)*a - (ushort)*b; |
| 474 | return (ushort)*a < (ushort)*b; |
458 | 475 | } |
459 | 476 | |
460 | 477 | inline bool String::operator<(const Latin1String &str) const |