Ticket #46496: fix_bug_in_internal_comparison_operator.patch

File fix_bug_in_internal_comparison_operator.patch, 2.3 KB (added by RJVB (René Bertin), 10 years ago)

from Ubuntu

  • qtbase/src/corelib/json/qjson_p.h

    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(-)
    
     
    352352        return !memcmp(d->utf16, str.d->utf16, d->length*sizeof(ushort));
    353353    }
    354354    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); }
    356356
    357357    inline QString toString() const {
    358358#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
     
    412412            val = d->length - str.d->length;
    413413        return val >= 0;
    414414    }
     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);
    415423
     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    }
    416433    inline bool operator ==(const String &str) const {
    417434        return (str == *this);
    418435    }
    419436    inline bool operator >=(const String &str) const {
    420         return (str < *this);
     437        return !(*this < str);
    421438    }
    422439
    423440    inline QString toString() const {
     
    454471        a++,b++;
    455472    if (l==-1)
    456473        return (alen < blen);
    457     return (ushort)*a - (ushort)*b;
     474    return (ushort)*a < (ushort)*b;
    458475}
    459476
    460477inline bool String::operator<(const Latin1String &str) const