diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2021-11-27 10:57:24 -0800 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-02-15 17:00:04 -0800 |
| commit | e99417106f4a2a7ef75cdf3317d950c30ad78ebe (patch) | |
| tree | 4fbcd73a4c1d5fa424b6752c05988a52432420b9 /src/corelib/serialization/qjsonobject.cpp | |
| parent | f276f9ec6bc187a7eebbc566fa3ce37311dbe871 (diff) | |
QJsonObject::erase: erase unnecessary and wrong code
Commit 35adb74ddd915831789f0175423660f8e898942e ("Reimplement JSON
support on top of Cbor") accidentally forgot to multiply by 2 the index
stored in the QJsonObject::iterator. The same mistake was propagated
when QJsonObject::iterator was converted to QJsonValueRef. This had no
ill effects because the o->elements container would always contain more
elements, but it meant the check was ineffective and meant nothing.
So instead of doing nothing when the iterator does not point to this
container, simply assume it does. Bad things will happen if you try to
erase an iterator that points to another container, but that's true for
almost all container/iterator mechanisms.
Drive-by modernization of some of the surrounding lines.
Change-Id: I89446ea06b5742efb194fffd16bb7c322c2fc4f2
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/serialization/qjsonobject.cpp')
| -rw-r--r-- | src/corelib/serialization/qjsonobject.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index 502d64d854b..014224c4db1 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -707,13 +707,12 @@ bool QJsonObject::operator!=(const QJsonObject &other) const */ QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it) { - if (it.item.o != this || qsizetype(it.item.index) >= o->elements.length()) - return {this, o->elements.length()}; - removeAt(it.item.index); - // iterator hasn't changed - return it; + // index hasn't changed; the container pointer shouldn't have changed + // because we shouldn't have detached (detaching happens on obtaining a + // non-const iterator). But just in case we did, reload the pointer. + return { this, qsizetype(it.item.index) }; } #if QT_STRINGVIEW_LEVEL < 2 |
