summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix test compilation issues with QtLite configurationJari Helaakoski3 days1-0/+12
| | | | | | | | | | Now developer build tests compile, but some are not working. Functional fix will come later via separate tasks. Task-number: QTBUG-122999 Change-Id: I70487b46c1b32ba4279cb02a4978e4f55ac0d310 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* CBOR: fix sorting of UTF16-to-UTF16 stringsThiago Macieira2024-04-121-30/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This amends commit 394788c68efacdec2676988b4b4ff207b20557f2 (its ChangeLog applies to this commit too). That fixed sorting of UTF8-to- UTF16, but when adding more unit tests, I've discovered that some UTF-16 strings also sorted incorrectly. There were two problems: First, we were assuming that we could rely on the UTF-16 length as a proxy for the UTF-8 one, but that's not true for some cases: * both 1-, 2- and 3-codepoint UTF-8 sequences are 1 codepoint in UTF-16, so some strings would have identical UTF-16 length * 4-codepoint UTF-8 sequences shrink to 2-codepoint UTF-16 ones (2:1) but 3-codepoint UTF-8 sequences shrink to 1 (3:1), so some strings would be longer in UTF-16 but shorter in UTF-8. Second, QtPrivate::compareStrings performs UTF-16 codepoint comparisons not Unicode character ones, so surrogate pairs were sorting before U+E000 to U+FFFF. To fix all of this, we need to decode the UTF-16 string into UTF-32 and calculate the length of that in UTF-8 to be sure we have the sorting order right. Since this is a slight behavior change with a performance penalty, I am choosing to backport only to 6.7. The penalty mostly does not apply to 6.8 due to commit 61556627f25e7c7acbfcc5e54127a392b5239977. Pick-to: 6.7 Change-Id: If1bf59ecbe014b569ba1fffd17c4c4ddcc874aac Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QCborMap iterators: use new comparison helper macrosTatiana Borisova2024-04-121-0/+19
| | | | | | | | | | | | | | | | | New comparison macros are used for following classes: - QCborMap::Iterator - QCborMap::ConstIterator Replace public operators operator==(), operator!=(), operator!<(), etc of classes to friend methods comparesEqual(), compareThreeWay(); Use *_helper methods to have an access to protected members of QCborValueConstRef class from friend functions. Task-number: QTBUG-120300 Change-Id: I71b6febaf3f31ea7ba668d91c375b0a7b6827d21 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QCborArray iterators: use new comparison helper macrosTatiana Borisova2024-04-101-0/+29
| | | | | | | | | | | | | | | | | New comparison macros are used for following classes: - QCborArray::Iterator - QCborArray::ConstIterator Replace public operators operator==(), operator!=(), operator!<(), etc of classes to friend methods comparesEqual(), compareThreeWay(); Use *_helper methods to have an access to protected members of QCborValueRef class from friend functions. Task-number: QTBUG-120300 Change-Id: Ie8ffef3e2278dfbf2bf0b32c30a7bf98d99fd1c3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_QCborValue: merge sorting() and comparison() testsThiago Macieira2024-04-081-91/+124
| | | | | | | | Drive-by add NaN value for testing. Change-Id: I5f663c2f9f4149af84fefffd17c035f099d01d55 Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QCborValue: fix sorting of UTF8-to-UTF16 stringsThiago Macieira2024-04-081-0/+36
| | | | | | | | | | | | | We must compare the raw string length in UTF-8, not the UTF-16 one. [ChangeLog][QtCore][QCborValue] Fixed a bug that caused certain non-US-ASCII string comparisons to produce results not in line with the CBOR specifications. Pick-to: 6.5 6.6 6.7 Change-Id: I5f663c2f9f4149af84fefffd17c05d1c0f1bbc3a Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QCborMap: add missing comparator to QCborValueConstRefThiago Macieira2024-03-261-2/+10
| | | | | | | | | And ensure all combination of CBOR types are tested. Amends e5ebb9022ab9e00ab01d0bce527755da77083217 Change-Id: I5f663c2f9f4149af84fefffd17c02d352cd41f3f Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
* QCborMap: use new comparison helper macrosTatiana Borisova2024-03-201-150/+169
| | | | | | | | | | | | | | | | | | | | | | Replace public operators operator==(), operator!=(), operator<() of QCborMap to friend methods comparesEqual() / compareThreeWay(). Use QT_CORE_REMOVED_SINCE to get rid of current comparison methods and replace them with a friend. Delete #if 0 && __has_include(<compare>) blocks, since they are not required anymore. Add friend methods comparesEqual(QCborMap, QCborValue) and compareThreeWay(QCborMap, QCborValue) to the QCborMap class, to support comparison between QCborMap and QCborValue elements, see test-case mapSelfAssign() -> QT_TEST_EQUALITY_OPS(it.key(), QCborMap({{0, v}}), true); Task-number: QTBUG-120300 Change-Id: I9e33df255d16484efd3124cf0632db859408fb5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QCborArray: use new comparison helper macrosTatiana Borisova2024-03-191-34/+51
| | | | | | | | | | | | | | | | | | | | | | | Replace public operators operator==(), operator!=(), operator<() of QCborArray to friend methods comparesEqual() / compareThreeWay(). Use QT_CORE_REMOVED_SINCE to get rid of current comparison methods and replace them with a friend. Delete #if 0 && __has_include(<compare>) blocks, since they are not required anymore. Add friend methods comparesEqual(QCborArray, QCborValueConstRef) and compareThreeWay(QCborArray, QCborValueConstRef) to QCborArray to support comparison between QCborArray and QCborValueRef/QCborValueConstRef, see test-case mapMutation(). Add QT_TEST_EQUALITY_OPS/QT_TEST_ALL_COMPARISON_OPS tests for QCborArray test-cases. Task-number: QTBUG-120300 Change-Id: Ifad1a04c61363618e8bba73cf7c87757552d722a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QCborValueConstRef/QCborValueRef: use new comparison helper macrosTatiana Borisova2024-03-191-7/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | Replace public operators operator==() and operator!=() of QCborValueConstRef and QCborValueRef classes to friend methods comparesEqual(). Replace public operator<() of QCborValueConstRef and QCborValueRef classes to friend methods compareThreeWay() respectively. Use QT_CORE_REMOVED_SINCE to get rid of current comparison methods and replace them with a friend. Delete #if 0 && __has_include(<compare>) blocks, since they are not required anymore. Add comparison() test-case for QCborValueConstRef/QCborValueRef testing. Add QCborValue::operator==()/QCborValue::operator!=()/ QCborValue::operator<() and QCborValueRef::operator==()/ QCborValueRef::operator!=()/QCborValueRef::operator<() operators to the removed_api file. Task-number: QTBUG-120300 Change-Id: I2e8e4e32b7b5b49da321364cc12986e9c64b5f37 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QCborValue: use new comparison helper macrosTatiana Borisova2024-03-131-56/+45
| | | | | | | | | | | | | | | | | | | Replace public operators operator==() and operator!=() of QCborValue to friend method comparesEqual(). Replace public operator<() of QCborValue to friend method compareThreeWay(). Use QT_CORE_REMOVED_SINCE to get rid of current comparison methods and replace them with a friend. Delete #if 0 && __has_include(<compare>) blocks, since they are not required anymore. Task-number: QTBUG-120300 Change-Id: I884ff6ce2a71618b0e3eaa907f0852f93c2a073c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Containers: add max_size()Giuseppe D'Angelo2024-02-271-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | One more method for STL compatibility. This one is particularly subtle as it's required by the `reservable-container` concept: https://eel.is/c++draft/ranges#range.utility.conv.general-3 Without this concept, ranges::to won't reserve() before copying the elements (out of a sized range which isn't a common_range). Implementation notes: there were already a couple of constants denoting the maximum QByteArray and QString size. Centralize that implementation in QTypedArrayData, so that QList can use it too. The maximum allocation size (private constant) needs a even more central place so that even QVLA can use it. Lacking anything better, I've put it in qcontainerfwd.h. Since our containers aren't allocator-aware, I can make max_size() a static member, and replace the existing constants throughout the rest of qtbase. (I can't kill them yet as they're used by other submodules.) [ChangeLog][QtCore][QList] Added max_size(). [ChangeLog][QtCore][QString] Added max_size(). [ChangeLog][QtCore][QByteArray] Added max_size(). [ChangeLog][QtCore][QVarLengthArray] Added max_size(). Change-Id: I176142e31b998f4f787c96333894b8f6653eb70d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Change license for tests filesLucie Gérard2024-02-041-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* CI: Enable tests under corelib/serialization for Wasm platformPiotr Wierciński2023-08-141-0/+5
| | | | | | | Add more tests on WebAssembly platform for better tests coverage. Change-Id: Iaaaa824ae6058a9ae5dba4c4038a7f687bfc17e0 Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
* Suppress a couple of GCC warningsAhmad Samir2023-06-291-0/+3
| | | | | | | | | | | They're already suppressed for clang. -Wself-move was added in GCC 13.1, the CI still doesn't have that so wrap it in an "#if Q_CC_GNU >= 1301". Change-Id: I5c2ec78a5003485261b4e3125f85c5b78dd0db22 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Adapt corelib to use QTimeZone in place of Qt::TimeSpecEdward Welbourne2022-12-091-28/+42
| | | | | | | | | This saves (mostly in corelib/time/) some complications that used to arise from needing different code-paths for different time-specs. Task-number: QTBUG-108199 Change-Id: I5dbd09859fce7599f1ba761f8a0bfc4633d0bef9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Ignore the warning for all types in tst_QCborValue's mapFromArray*()Edward Welbourne2022-10-181-6/+1
| | | | | | | | | For some reason the QTest::ignoreMessage() was conditioned on the type being tested being Array; however, the warning is in fact produced for all types. So anticipate it for all and make the test log less noisy. Change-Id: I78681624252ff8a71f080204f8b031609ddac468 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-111-12/+12
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* tst_QCborValue: remove duplicate data row from testsEdward Welbourne2022-10-111-1/+0
| | | | | | | | The addCommonCborData() helper had two identical rows named simple255. It only needs one. Change-Id: Ie934c31f373069788c3ef774fde8956b54814e67 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QCborArray: allow large but in-range keysThiago Macieira2022-02-151-0/+25
| | | | | | | | The 0x10000 limit should not apply if the key is a valid index in the array. Change-Id: I5e52dc5b093c43a3b678fffd16b6a2a5a69acd61 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Introduce Q{Json,Cbor}ValueConstRefThiago Macieira2022-02-151-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I screwed up when I wrote QCborValueRef by not having the ConstRef type. The code worked, but it wasn't const-correct, allowing you to write: const QCborArray &arr = something(); *arr.begin() = QCborArray(); This mistake was brought over to QJsonValue in Qt 6.0, so it has to be fixed for QJsonValue too. The actual fixes are in the next couple of commits. This change is believed to be binary-compatible: the Q{Json,Cbor}ValueRef classes continue to have the exact same size, except that they're now empty and have a new base class. They weren't trivial before this commit doesn't change that. [ChangeLog][Potentially Source-Incompatible Changes] The iterator classes for Qt's JSON and CBOR containers (array and map/object) had a const correctness issue which allowed a const_iterator to mutate the container being iterated on, even if that container was itself const. Qt 6.4 has a fix for this, but will cause compilation issues where QCborValueRef and QJsonValueRef were used where the correctness could be violated. To keep code compiling with both 6.3 and 6.4, either change to non-const iteration or replace the QxxxValueRef with a const QxxxValue reference. This change is binary-compatible. Change-Id: I5e52dc5b093c43a3b678fffd16b6063333765ae0 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QCborValueRef: fix using operator[] to convert an empty array to mapThiago Macieira2022-02-151-8/+207
| | | | | | | | | | | The flag IsContainer was not set, causing the QCborContainerPrivate to become confused. This commit also expands and subsumes the existing test for QCborValue (non-Ref). Change-Id: I5e52dc5b093c43a3b678fffd16b6a17c6f4a0676 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValueRef: add a test to confirm that its methods reflect QCborValueThiago Macieira2022-02-151-1/+163
| | | | | | | | | | | This has found several missing const qualifications, a missing QCborMap::Iterator method, and a missing one in QCborValue too. The methods "### TEMPORARY" in this commit are actually removed in two commits. Change-Id: I5e52dc5b093c43a3b678fffd16b6939f62954dc4 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QCborValue: fix incorrect to{Array,Map} when the value is emptyThiago Macieira2022-02-031-0/+87
| | | | | | | | | | When QCborValue referred to an empty array or map, toArray() and toMap() would respectively return the default value instead of the empty object, as expected. Pick-to: 6.2 6.3 Change-Id: I5e52dc5b093c43a3b678fffd16b60456d0037ad7 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix compiler warning from int size mismatchVolker Hilsheimer2021-04-291-2/+2
| | | | | | | | Cast consistently to quint8, which is the type we are streaming out in the test. Change-Id: I44d360ca6b75f14e7a2b80962ad249a6f6b1cb31 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace QtTest headers with QTestDavid Skoland2020-12-221-1/+5
| | | | | | | | | | | Complete search and replace of QtTest and QtTest/QtTest with QTest, as QtTest includes the whole module. Replace all such instances with correct header includes. See Jira task for more discussion. Fixes: QTBUG-88831 Change-Id: I981cfae18a1cabcabcabee376016b086d9d01f44 Pick-to: 6.0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* tst_QCborValue: adjust the size of the minimum string that won't fitThiago Macieira2020-12-071-1/+3
| | | | | | | | | I don't know which of the previous commits caused this: as far as I can tell, this test should never have passed. Pick-to: 5.15 6.0 Change-Id: I55083c2909f64a1f8868fffd164e7e8c24eec1f8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QCborValue: avoid allocating result if data is insufficientThiago Macieira2020-12-061-4/+2
| | | | | | | | | | | Similar to the previous commit which applied to QCborStreamReader, don't allocate too much data before checking that the stream actually has that much. Pick-to: 5.15 6.0 Fixes: QTBUG-88256 Change-Id: I7b9b97ae9b32412abdc6fffd16454b7568a063ba Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* QCborStreamReader: avoid allocating result if data is insufficientThiago Macieira2020-12-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | | By calling the internal readStringChunk() function with a QByteArray pointer, QCborStreamReader::readByteArray() can now avoid allocating the resulting buffer until the internals have confirmed that there is sufficient data in the incoming buffer. As a result, we first detect the EOF condition before we conclude the payload would have been too big for QByteArray (validation()) test. Meanwhile, the hugeDeviceValidation() test ends up with a few conditions where it would have copied 1 GB of data, so limit that too. We make a choice of reporting OOM vs DataTooLarge only if QByteArray fails to allocate in the first place (QByteArray::resize() -> Q_CHECK_PTR -> qBadAlloc, QtCore is always built with exceptions on). The QCborValue unit test needed a temporary work around until we apply the same allocation fix (see next commit). Pick-to: 5.15 6.0 Fixes: QTBUG-88253 Change-Id: I7b9b97ae9b32412abdc6fffd164523eeae49cdfe Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Fix some compiler warnings from testsVolker Hilsheimer2020-10-161-1/+1
| | | | | | | | For iterators that return a value, don't use reference in ranged for, and cast numeric literal to correct size type for QCOMPARE. Change-Id: Idfd09dbc2ef3ab1bf025c7859ea6e2e9572bc9a1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Change QByteArray to handle large arraysLars Knoll2020-08-271-2/+2
| | | | | | | | | | Use qsizetype throughout. Change-Id: I787af7fcfa17e1be87decb64c41c609cc24be117 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QCborValue: add support for QCOMPARE string outputThiago Macieira2020-08-121-2/+138
| | | | | | Change-Id: Ibdc95e9af7bd456a94ecfffd16066c47ea9766d0 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Disable warning about self-move and self-assign-overloadTor Arne Vestbø2020-07-261-0/+3
| | | | | Change-Id: I1d20d3f424eced5cc5787934663b9d243f75d46e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix warning when printing of qsizetypeTor Arne Vestbø2020-07-261-1/+1
| | | | | | | warning: format specifies type 'int' but the argument has type 'qsizetype' (aka 'long long') Change-Id: I6099b53efecea46d191d5dc019c986f99e49c1f1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use QList instead of QVector in corelib testsJarek Kobus2020-07-071-1/+1
| | | | | | Task-number: QTBUG-84469 Change-Id: Ic80fde5517aed363f17d0da55cadcc958c3c8895 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Use qsizetype in QListLars Knoll2020-07-061-2/+2
| | | | | | | | | | | | | | | | | | | | The change creates a slight source incompatibility. The main things to take care of are * code using printf statements on list.size(). Using qsizetype in printf statements will always require a cast to work on both 32 and 64 bit. * A few places where overloads now get ambiguous. One example is QRandomGenerator::bounded() that has overloads for int, uint and double, but not int64. * Streaming list.size() to a QDataStream will change the format depending on the architecture. [ChangeLog][QtCore][QList] QList now uses qsizetype to index into elements. Change-Id: Iaff562a4d072b97f458417b670f95971bd47cbc6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QCborMap: remove the optimization not to detach from non-const find()Thiago Macieira2020-06-231-0/+62
| | | | | | | | | | | | | | | | | All our tests were find() == end() or !=, which depends on the evaluation order of the arguments to operator==(). If end() is called first, then the detach happens before find() and all is well. But if find() is called first, it may return end() before end() detaches. [ChangeLog][QCborMap] Fixed a bug that could cause the iterator returned from a failing key search with find() not to match end(). Now, every call to find() will detach in shared QCborMaps; to avoid this, use constFind() and constEnd(). Fixes: QTBUG-84583 Pick-to: 5.15 5.12 Change-Id: I552d244076a447ab92d7fffd161793496a8d03a8 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QCborValue: catch overflow in QByteArray when decoding chunked stringsThiago Macieira2020-05-071-1/+14
| | | | | | | | | | We checked against integer overflow, but not against overflowing the QByteArray size limit. That caused a std::bad_alloc to be thrown, which is bad when decoding unknown data. QCborStreamReader wasn't affected, since it doesn't merge chunks. Change-Id: I99ab0f318b1c43b89888fffd160c36f495fada87 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QCborValue: check parsing of invalid URLThiago Macieira2020-04-301-0/+8
| | | | | | | | | QUrl will reject invalid URLs for us, so we don't get normalization. The original junk should be retrievable, of course. Change-Id: Ibdc95e9af7bd456a94ecfffd160610f5b2c8e1a2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValue: add tests of parsing invalid ISO date-time stringsThiago Macieira2020-04-301-4/+72
| | | | | | | | | We rely on QDateTime::fromString being proper, so this is not extensive testing. Change-Id: Ibdc95e9af7bd456a94ecfffd160610cdac5d62e1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValue: add an extra check against producing invalid ISO datesThiago Macieira2020-04-301-0/+15
| | | | | | | | | By QCborValue design, we store the textual representation in ISO format, equivalent of CBOR tag 0, which isn't allowed to have negative years or beyond year 10000. Change-Id: Ibdc95e9af7bd456a94ecfffd16060ccff359c296 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QCborValue: avoid signed integer oveflows when decoding time_tThiago Macieira2020-04-301-0/+109
| | | | | | | | | | | | QDateTime::fromSecsSinceEpoch() multiplies by 1000 but does not check for overflow. That means we must do so in QCborValue validation. We can't use mul_overflow<qint64> on 32-bit platforms, so we do a compare- and-branch there. For 64-bit platforms, we prefer to do the multiplication with checked overflow, as the common case is that it will not overflow and we'll need the multiplication anyway. Change-Id: Ibdc95e9af7bd456a94ecfffd16060cba6f1c86b8 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValue: fix the move-assignment operatorv5.15.0-beta4Thiago Macieira2020-04-111-0/+12
| | | | | | | | | | | | | | | | | | | | The double-swap technique I used was flawed and broke on self-assignment. What I had meant to use was the move-and-swap technique. Thanks to Peppe for pointing it out. This also fixes a compiler bug in the Green Hills compiler. It was finding the wrong "swap" function in qSwap: using std::swap; swap(value1, value2); It's supposed to find swap(QCborValue &, QCborValue &) due to argument- dependent lookup. It's instead finding std::swap<QCborValue>, which recurses. Fixes: QTBUG-83390 Change-Id: Ibdc95e9af7bd456a94ecfffd1603e1bee90cd107 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QCborArray: fix operator[] that extends the arrayThiago Macieira2020-04-091-0/+54
| | | | | | | | | | | This was never tested. The infinite loop in QCborContainerPrivate::grow is the proof. [ChangeLog][QtCore][QCborArray] Fixed an infinite loop when operator[] was called with with an index larger than the array's size plus 1. Change-Id: Ibdc95e9af7bd456a94ecfffd1603df3855c73f20 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QCborMap: fix assigning elements from the map to itselfThiago Macieira2020-04-091-0/+71
| | | | | | | | | | | | | | | | | | | | | | | Similar to the QJsonObject issue of the previous commit (found with the same tests, but not the same root cause). One fix was that copying of byte data from the QByteArray to itself won't work if the array reallocates. The second was that assign(*that, other.concrete()); fails to set other.d to null after moving. By calling the operator=, we get the proper sequence of events. [ChangeLog][QtCore][QCborMap] Fixed some issues relating to assigning elements from a map to itself. Note: QCborMap is not affected by the design flaw discovered in QJsonObject because it always appends elements (it's unsorted), so existing QCborValueRef references still refer to the same value. Task-number: QTBUG-83366 Change-Id: Ibdc95e9af7bd456a94ecfffd1603df846f46094d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* tst_QCborValue: Prepare for 64-bit QVectors in Qt 6Thiago Macieira2020-03-271-7/+15
| | | | | Change-Id: Ief61acdfbe4d4b5ba1f0fffd15fe1e921aab0a72 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* CBOR support: prevent overflowing QByteArray's max allocationThiago Macieira2020-03-271-10/+42
| | | | | | | | | | | | QByteArray doesn't like it. Apply the same protection to QString, which we know uses the same backend but uses elements twice as big. That means it can contain slightly more than half as many elements, but exact half will suffice for our needs. Change-Id: Iaa63461109844e978376fffd15f9d4c7a9137856 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QCborValue::fromCbor: Apply a recursion limit to decodingThiago Macieira2020-03-251-0/+54
| | | | | | | | | | | | | | | | | | | A simple 16k file can produce deep enough recursion in Qt to cause stack overflow. So prevent that. I tested 4096 recursions just fine on my Linux system (8 MB stack), but decided 1024 was sufficient, as this code will also be run on embedded systems that could have smaller stacks. [ChangeLog][QtCore][QCborValue] fromCbor() now limits decoding to at most 1024 nested maps, arrays, and tags to prevent stack overflows. This should be sufficient for most uses of CBOR. An API to limit further or to relax the limit will be provided in 5.15. Meanwhile, if decoding more is required, QCborStreamReader can be used (note that each level of map and array allocates memory). Change-Id: Iaa63461109844e978376fffd15fa0fbefbf607a2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Don't wrap feature detection macros with QT_HAS_FOO() variantsTor Arne Vestbø2019-12-101-1/+1
| | | | | | | | | | | | | | | | | Using wrappers for these macros is problematic when for example passing the -frewrite-includes flag to preprocess sources before shipping off to distcc or Icecream. It will also start producing warnings when compilers implement http://eel.is/c++draft/cpp.cond#7.sentence-2. See for example https://reviews.llvm.org/D49091 Both https://clang.llvm.org/docs/LanguageExtensions.html and the SD-6 document at https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations recommend defining '__has_foo(x) 0' as a fallback for compilers without the macros, so that's what we go for. Change-Id: I0298cd3b4a6ff6618821e34642a5ddd6728be767 Reviewed-by: Alex Richardson <arichardson.kde@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>