summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/tinycbor
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/tinycbor')
-rw-r--r--src/3rdparty/tinycbor/0001-tst_Encoder-port-away-from-Q_FOREACH.patch79
-rw-r--r--src/3rdparty/tinycbor/qt_attribution.json7
-rw-r--r--src/3rdparty/tinycbor/src/cbor.h10
-rw-r--r--src/3rdparty/tinycbor/src/cborencoder.c74
-rw-r--r--src/3rdparty/tinycbor/src/cborerrorstrings.c2
-rw-r--r--src/3rdparty/tinycbor/src/cborinternal_p.h14
-rw-r--r--src/3rdparty/tinycbor/src/cborparser.c8
-rw-r--r--src/3rdparty/tinycbor/src/compilersupport_p.h2
-rw-r--r--src/3rdparty/tinycbor/tests/.gitignore2
-rw-r--r--src/3rdparty/tinycbor/tests/encoder/data.cpp63
-rw-r--r--src/3rdparty/tinycbor/tests/encoder/encoder.pro9
-rw-r--r--src/3rdparty/tinycbor/tests/encoder/tst_encoder.cpp17
-rw-r--r--src/3rdparty/tinycbor/tests/parser/data.cpp28
-rw-r--r--src/3rdparty/tinycbor/tests/parser/parser.pro10
-rw-r--r--src/3rdparty/tinycbor/tests/parser/tst_parser.cpp52
15 files changed, 263 insertions, 114 deletions
diff --git a/src/3rdparty/tinycbor/0001-tst_Encoder-port-away-from-Q_FOREACH.patch b/src/3rdparty/tinycbor/0001-tst_Encoder-port-away-from-Q_FOREACH.patch
new file mode 100644
index 0000000000..43c8b1a452
--- /dev/null
+++ b/src/3rdparty/tinycbor/0001-tst_Encoder-port-away-from-Q_FOREACH.patch
@@ -0,0 +1,79 @@
+From b6e2caf7452bf2b695583196fd7b346c1663d798 Mon Sep 17 00:00:00 2001
+From: Marc Mutz <marc.mutz@qt.io>
+Date: Mon, 7 Aug 2023 16:24:13 +0200
+Subject: [PATCH] tst_Encoder: port away from Q_FOREACH
+
+Qt is defaulting to QT_NO_FOREACH these days, so make sure we
+integrate nicely with downstream and fix the single Q_FOREACH/foreach
+user, in tst_encoder.cpp.
+
+Unfortunately, the container's initialization code doesn't exactly
+lend itself to making the container const (not even IILE
+(Immediately-Invoked Lambda Expression) would help here, due to the
+interdependency with `len`), so the idiomatic solution would be to use
+std::as_const()/qAsConst().
+
+The former is available from C++17, which we don't require, yet, and
+the latter is not available under QT_NO_AS_CONST (the default for Qt
+these days), so grab the nettle and implement a t17::as_const() that
+switches between a manual implementation of std::as_const and the real
+thing, depending on __cpp_lib_as_const. The `t17` here mimicks the qNN
+(q20::remove_cvref_t/q23::forward_like/etc) mechanism used in Qt
+itself for backports, with s/q/t/ because ... _T_inyCbor.
+
+The t17 implementation is local to tst_encoder.cpp, but can easily be
+extracted into a separate header once more users emerge.
+---
+ tests/encoder/encoder.pro | 2 ++
+ tests/encoder/tst_encoder.cpp | 15 ++++++++++++++-
+ 2 files changed, 16 insertions(+), 1 deletion(-)
+
+diff --git a/tests/encoder/encoder.pro b/tests/encoder/encoder.pro
+index 62d9b7e..180f0d7 100644
+--- a/tests/encoder/encoder.pro
++++ b/tests/encoder/encoder.pro
+@@ -3,6 +3,8 @@ SOURCES += tst_encoder.cpp
+ CONFIG += testcase parallel_test c++11
+ QT = core testlib
+
++DEFINES += QT_NO_FOREACH QT_NO_AS_CONST
++
+ INCLUDEPATH += ../../src
+ msvc: POST_TARGETDEPS = ../../lib/tinycbor.lib
+ else: POST_TARGETDEPS += ../../lib/libtinycbor.a
+diff --git a/tests/encoder/tst_encoder.cpp b/tests/encoder/tst_encoder.cpp
+index 31c2915..61ce9c9 100644
+--- a/tests/encoder/tst_encoder.cpp
++++ b/tests/encoder/tst_encoder.cpp
+@@ -29,6 +29,19 @@
+ #include <qfloat16.h>
+ #endif
+
++#include <utility>
++namespace t17 {
++#ifdef __cpp_lib_as_const
++ using std::as_const;
++#else
++ template <typename T>
++ constexpr typename std::add_const<T>::type &as_const(T &t) noexcept { return t; }
++ // prevent rvalue arguments:
++ template <typename T>
++ void as_const(const T &&) = delete;
++#endif // __cpp_lib_as_const
++} // namespace t17
++
+ Q_DECLARE_METATYPE(CborError)
+ namespace QTest {
+ template<> char *toString<CborError>(const CborError &err)
+@@ -153,7 +166,7 @@ CborError encodeVariant(CborEncoder *encoder, const QVariant &v)
+ CborError err = cbor_encoder_create_array(encoder, &sub, len);
+ if (err && !isOomError(err))
+ return err;
+- foreach (const QVariant &v2, list) {
++ for (const QVariant &v2 : t17::as_const(list)) {
+ err = static_cast<CborError>(err | encodeVariant(&sub, v2));
+ if (err && !isOomError(err))
+ return err;
+--
+2.25.1
+
diff --git a/src/3rdparty/tinycbor/qt_attribution.json b/src/3rdparty/tinycbor/qt_attribution.json
index 5b6355d013..b19c57904b 100644
--- a/src/3rdparty/tinycbor/qt_attribution.json
+++ b/src/3rdparty/tinycbor/qt_attribution.json
@@ -3,13 +3,14 @@
"Name": "TinyCBOR",
"QDocModule": "qtcore",
"QtUsage": "Used for QCborStreamReader and QCborStreamWriter.",
+ "SecurityCritical": true,
"Description": "Concise Binary Object Representation (CBOR) Library",
- "Version": "0.6.0",
"Homepage": "https://github.com/intel/tinycbor",
"License": "MIT License",
"LicenseId": "MIT",
"LicenseFile": "LICENSE",
- "Version": "0.6+patches",
- "Copyright": "Copyright (C) 2018 Intel Corporation"
+ "DownloadLocation": "https://github.com/intel/tinycbor/archive/v0.6.0/tinycbor-0.6.0.tar.gz",
+ "Version": "0.6.0",
+ "Copyright": "Copyright (C) 2015-2021 Intel Corporation"
}
diff --git a/src/3rdparty/tinycbor/src/cbor.h b/src/3rdparty/tinycbor/src/cbor.h
index 3672bd0d98..be5bbc77a3 100644
--- a/src/3rdparty/tinycbor/src/cbor.h
+++ b/src/3rdparty/tinycbor/src/cbor.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
@@ -263,10 +263,10 @@ CBOR_INLINE_API CborError cbor_encode_float(CborEncoder *encoder, float value)
CBOR_INLINE_API CborError cbor_encode_double(CborEncoder *encoder, double value)
{ return cbor_encode_floating_point(encoder, CborDoubleType, &value); }
-CBOR_API CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length);
-CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length);
-CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder);
-CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);
+CBOR_API CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arrayEncoder, size_t length);
+CBOR_API CborError cbor_encoder_create_map(CborEncoder *parentEncoder, CborEncoder *mapEncoder, size_t length);
+CBOR_API CborError cbor_encoder_close_container(CborEncoder *parentEncoder, const CborEncoder *containerEncoder);
+CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *parentEncoder, const CborEncoder *containerEncoder);
CBOR_INLINE_API uint8_t *_cbor_encoder_get_buffer_pointer(const CborEncoder *encoder)
{
diff --git a/src/3rdparty/tinycbor/src/cborencoder.c b/src/3rdparty/tinycbor/src/cborencoder.c
index 38804cfa6f..a51f445159 100644
--- a/src/3rdparty/tinycbor/src/cborencoder.c
+++ b/src/3rdparty/tinycbor/src/cborencoder.c
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
@@ -65,7 +65,7 @@
* \code
* uint8_t buf[16];
* CborEncoder encoder;
- * cbor_encoder_init(&encoder, &buf, sizeof(buf), 0);
+ * cbor_encoder_init(&encoder, buf, sizeof(buf), 0);
* cbor_encode_int(&encoder, some_value);
* \endcode
*
@@ -117,16 +117,16 @@
* CborEncoder encoder, mapEncoder;
* cbor_encoder_init(&encoder, buf, sizeof(buf), 0);
* err = cbor_encoder_create_map(&encoder, &mapEncoder, 1);
- * if (!err)
+ * if (err)
* return err;
* err = cbor_encode_text_stringz(&mapEncoder, "foo");
- * if (!err)
+ * if (err)
* return err;
* err = cbor_encode_boolean(&mapEncoder, some_value);
- * if (!err)
+ * if (err)
* return err;
* err = cbor_encoder_close_container_checked(&encoder, &mapEncoder);
- * if (!err)
+ * if (err)
* return err;
*
* size_t len = cbor_encoder_get_buffer_size(&encoder, buf);
@@ -157,7 +157,7 @@
*
* cbor_encoder_init(&encoder, buf, size, 0);
* err = cbor_encoder_create_array(&encoder, &arrayEncoder, n);
- * cbor_assert(err); // can't fail, the buffer is always big enough
+ * cbor_assert(!err); // can't fail, the buffer is always big enough
*
* for (i = 0; i < n; ++i) {
* err = cbor_encode_text_stringz(&arrayEncoder, strings[i]);
@@ -166,7 +166,7 @@
* }
*
* err = cbor_encoder_close_container_checked(&encoder, &arrayEncoder);
- * cbor_assert(err); // shouldn't fail!
+ * cbor_assert(!err); // shouldn't fail!
*
* more_bytes = cbor_encoder_get_extra_bytes_needed(encoder);
* if (more_size) {
@@ -222,8 +222,8 @@ void cbor_encoder_init_writer(CborEncoder *encoder, CborEncoderWriteFunction wri
static inline void put16(void *where, uint16_t v)
{
- v = cbor_htons(v);
- memcpy(where, &v, sizeof(v));
+ uint16_t v_be = cbor_htons(v);
+ memcpy(where, &v_be, sizeof(v_be));
}
/* Note: Since this is currently only used in situations where OOM is the only
@@ -243,14 +243,14 @@ static inline bool isOomError(CborError err)
static inline void put32(void *where, uint32_t v)
{
- v = cbor_htonl(v);
- memcpy(where, &v, sizeof(v));
+ uint32_t v_be = cbor_htonl(v);
+ memcpy(where, &v_be, sizeof(v_be));
}
static inline void put64(void *where, uint64_t v)
{
- v = cbor_htonll(v);
- memcpy(where, &v, sizeof(v));
+ uint64_t v_be = cbor_htonll(v);
+ memcpy(where, &v_be, sizeof(v_be));
}
static inline bool would_overflow(CborEncoder *encoder, size_t len)
@@ -462,11 +462,10 @@ static CborError encode_string(CborEncoder *encoder, size_t length, uint8_t shif
*/
/**
- * Appends the text string \a string of length \a length to the CBOR stream
- * provided by \a encoder. CBOR requires that \a string be valid UTF-8, but
- * TinyCBOR makes no verification of correctness.
+ * Appends the byte string \a string of length \a length to the CBOR stream
+ * provided by \a encoder. CBOR byte strings are arbitrary raw data.
*
- * \sa CborError cbor_encode_text_stringz, cbor_encode_byte_string
+ * \sa cbor_encode_text_stringz, cbor_encode_text_string
*/
CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, size_t length)
{
@@ -474,10 +473,11 @@ CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, s
}
/**
- * Appends the byte string \a string of length \a length to the CBOR stream
- * provided by \a encoder. CBOR byte strings are arbitrary raw data.
+ * Appends the text string \a string of length \a length to the CBOR stream
+ * provided by \a encoder. CBOR requires that \a string be valid UTF-8, but
+ * TinyCBOR makes no verification of correctness.
*
- * \sa cbor_encode_text_stringz, cbor_encode_text_string
+ * \sa CborError cbor_encode_text_stringz, cbor_encode_byte_string
*/
CborError cbor_encode_text_string(CborEncoder *encoder, const char *string, size_t length)
{
@@ -514,7 +514,7 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container,
}
/**
- * Creates a CBOR array in the CBOR stream provided by \a encoder and
+ * Creates a CBOR array in the CBOR stream provided by \a parentEncoder and
* initializes \a arrayEncoder so that items can be added to the array using
* the CborEncoder functions. The array must be terminated by calling either
* cbor_encoder_close_container() or cbor_encoder_close_container_checked()
@@ -523,17 +523,17 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container,
* The number of items inserted into the array must be exactly \a length items,
* otherwise the stream is invalid. If the number of items is not known when
* creating the array, the constant \ref CborIndefiniteLength may be passed as
- * length instead.
+ * length instead, and an indefinite length array is created.
*
* \sa cbor_encoder_create_map
*/
-CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length)
+CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arrayEncoder, size_t length)
{
- return create_container(encoder, arrayEncoder, length, ArrayType << MajorTypeShift);
+ return create_container(parentEncoder, arrayEncoder, length, ArrayType << MajorTypeShift);
}
/**
- * Creates a CBOR map in the CBOR stream provided by \a encoder and
+ * Creates a CBOR map in the CBOR stream provided by \a parentEncoder and
* initializes \a mapEncoder so that items can be added to the map using
* the CborEncoder functions. The map must be terminated by calling either
* cbor_encoder_close_container() or cbor_encoder_close_container_checked()
@@ -542,7 +542,7 @@ CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEnco
* The number of pair of items inserted into the map must be exactly \a length
* items, otherwise the stream is invalid. If the number is not known
* when creating the map, the constant \ref CborIndefiniteLength may be passed as
- * length instead.
+ * length instead, and an indefinite length map is created.
*
* \b{Implementation limitation:} TinyCBOR cannot encode more than SIZE_MAX/2
* key-value pairs in the stream. If the length \a length is larger than this
@@ -551,11 +551,11 @@ CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEnco
*
* \sa cbor_encoder_create_array
*/
-CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length)
+CborError cbor_encoder_create_map(CborEncoder *parentEncoder, CborEncoder *mapEncoder, size_t length)
{
if (length != CborIndefiniteLength && length > SIZE_MAX / 2)
return CborErrorDataTooLarge;
- return create_container(encoder, mapEncoder, length, MapType << MajorTypeShift);
+ return create_container(parentEncoder, mapEncoder, length, MapType << MajorTypeShift);
}
/**
@@ -570,21 +570,21 @@ CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder,
*
* \sa cbor_encoder_create_array(), cbor_encoder_create_map()
*/
-CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder)
+CborError cbor_encoder_close_container(CborEncoder *parentEncoder, const CborEncoder *containerEncoder)
{
- if (encoder->end && !(encoder->flags & CborIteratorFlag_WriterFunction))
- encoder->data.ptr = containerEncoder->data.ptr;
- else
- encoder->data.bytes_needed = containerEncoder->data.bytes_needed;
- encoder->end = containerEncoder->end;
+ // synchronise buffer state with that of the container
+ parentEncoder->end = containerEncoder->end;
+ parentEncoder->data = containerEncoder->data;
+
if (containerEncoder->flags & CborIteratorFlag_UnknownLength)
- return append_byte_to_buffer(encoder, BreakByte);
+ return append_byte_to_buffer(parentEncoder, BreakByte);
if (containerEncoder->remaining != 1)
return containerEncoder->remaining == 0 ? CborErrorTooManyItems : CborErrorTooFewItems;
- if (!encoder->end)
+ if (!parentEncoder->end)
return CborErrorOutOfMemory; /* keep the state */
+
return CborNoError;
}
diff --git a/src/3rdparty/tinycbor/src/cborerrorstrings.c b/src/3rdparty/tinycbor/src/cborerrorstrings.c
index 1dd8ae25bd..44f766a3c4 100644
--- a/src/3rdparty/tinycbor/src/cborerrorstrings.c
+++ b/src/3rdparty/tinycbor/src/cborerrorstrings.c
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
diff --git a/src/3rdparty/tinycbor/src/cborinternal_p.h b/src/3rdparty/tinycbor/src/cborinternal_p.h
index c5fe63003f..16269e6301 100644
--- a/src/3rdparty/tinycbor/src/cborinternal_p.h
+++ b/src/3rdparty/tinycbor/src/cborinternal_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
@@ -37,15 +37,17 @@
#endif
#ifndef CBOR_NO_HALF_FLOAT_TYPE
-# ifdef __F16C__
+# if defined(__F16C__) || defined(__AVX2__)
# include <immintrin.h>
-static inline unsigned short encode_half(double val)
+static inline unsigned short encode_half(float val)
{
- return _cvtss_sh((float)val, 3);
+ __m128i m = _mm_cvtps_ph(_mm_set_ss(val), _MM_FROUND_CUR_DIRECTION);
+ return _mm_extract_epi16(m, 0);
}
-static inline double decode_half(unsigned short half)
+static inline float decode_half(unsigned short half)
{
- return _cvtsh_ss(half);
+ __m128i m = _mm_cvtsi32_si128(half);
+ return _mm_cvtss_f32(_mm_cvtph_ps(m));
}
# else
/* software implementation of float-to-fp16 conversions */
diff --git a/src/3rdparty/tinycbor/src/cborparser.c b/src/3rdparty/tinycbor/src/cborparser.c
index 2019e7b808..80c44c7e13 100644
--- a/src/3rdparty/tinycbor/src/cborparser.c
+++ b/src/3rdparty/tinycbor/src/cborparser.c
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
@@ -232,7 +232,7 @@ static CborError preparse_value(CborValue *it)
case SinglePrecisionFloat:
case DoublePrecisionFloat:
it->flags |= CborIteratorFlag_IntegerValueTooLarge;
- /* fall through */
+ Q_FALLTHROUGH();
case TrueValue:
case NullValue:
case UndefinedValue:
@@ -913,7 +913,7 @@ CborError cbor_value_get_int_checked(const CborValue *value, int *result)
/**
* \fn bool cbor_value_is_byte_string(const CborValue *value)
*
- * Returns true if the iterator \a value is valid and points to a CBOR text
+ * Returns true if the iterator \a value is valid and points to a CBOR byte
* string. CBOR byte strings are binary data with no specified encoding or
* format.
*
@@ -1147,7 +1147,7 @@ static CborError get_string_chunk(CborValue *it, const void **bufferptr, size_t
*/
CborError _cbor_value_get_string_chunk(const CborValue *value, const void **bufferptr,
- size_t *len, CborValue *next)
+ size_t *len, CborValue *next)
{
CborValue tmp;
if (!next)
diff --git a/src/3rdparty/tinycbor/src/compilersupport_p.h b/src/3rdparty/tinycbor/src/compilersupport_p.h
index bd10efc9c7..0879801611 100644
--- a/src/3rdparty/tinycbor/src/compilersupport_p.h
+++ b/src/3rdparty/tinycbor/src/compilersupport_p.h
@@ -44,7 +44,7 @@
# include <stdbool.h>
#endif
-#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L || __cpp_static_assert >= 200410
+#if __STDC_VERSION__ >= 201112L || (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__cpp_static_assert) && __cpp_static_assert >= 200410)
# define cbor_static_assert(x) static_assert(x, #x)
#elif !defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && (__STDC_VERSION__ > 199901L)
# define cbor_static_assert(x) _Static_assert(x, #x)
diff --git a/src/3rdparty/tinycbor/tests/.gitignore b/src/3rdparty/tinycbor/tests/.gitignore
index e65577d287..f5db2a8224 100644
--- a/src/3rdparty/tinycbor/tests/.gitignore
+++ b/src/3rdparty/tinycbor/tests/.gitignore
@@ -5,6 +5,8 @@ release
target_wrapper.*
# The executables
+c90/c90
+c90/c90.exe
cpp/cpp
cpp/cpp.exe
encoder/encoder
diff --git a/src/3rdparty/tinycbor/tests/encoder/data.cpp b/src/3rdparty/tinycbor/tests/encoder/data.cpp
index 8b00cfec1f..dc7c6a91a1 100644
--- a/src/3rdparty/tinycbor/tests/encoder/data.cpp
+++ b/src/3rdparty/tinycbor/tests/encoder/data.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
@@ -24,7 +24,29 @@
#include <QtTest>
-static float myNaNf()
+struct NegativeInteger { quint64 abs; };
+Q_DECLARE_METATYPE(NegativeInteger)
+
+struct SimpleType { uint8_t type; };
+Q_DECLARE_METATYPE(SimpleType)
+
+struct Float16Standin { uint16_t val; };
+Q_DECLARE_METATYPE(Float16Standin)
+
+struct Tag { CborTag tag; QVariant tagged; };
+Q_DECLARE_METATYPE(Tag)
+
+typedef QVector<QPair<QVariant, QVariant>> Map;
+Q_DECLARE_METATYPE(Map)
+
+struct IndeterminateLengthArray : QVariantList { using QVariantList::QVariantList; };
+struct IndeterminateLengthMap : Map { using Map::Map; };
+Q_DECLARE_METATYPE(IndeterminateLengthArray)
+Q_DECLARE_METATYPE(IndeterminateLengthMap)
+
+namespace {
+
+float myNaNf()
{
uint32_t v = 0x7fc00000;
float f;
@@ -33,7 +55,7 @@ static float myNaNf()
return f;
}
-static float myInff()
+float myInff()
{
uint32_t v = 0x7f800000;
float f;
@@ -42,7 +64,7 @@ static float myInff()
return f;
}
-static float myNInff()
+float myNInff()
{
uint32_t v = 0xff800000;
float f;
@@ -51,7 +73,7 @@ static float myNInff()
return f;
}
-static double myNaN()
+double myNaN()
{
uint64_t v = UINT64_C(0x7ff8000000000000);
double f;
@@ -60,7 +82,7 @@ static double myNaN()
return f;
}
-static double myInf()
+double myInf()
{
uint64_t v = UINT64_C(0x7ff0000000000000);
double f;
@@ -69,7 +91,7 @@ static double myInf()
return f;
}
-static double myNInf()
+double myNInf()
{
uint64_t v = UINT64_C(0xfff0000000000000);
double f;
@@ -83,36 +105,17 @@ template <size_t N> QByteArray raw(const char (&data)[N])
return QByteArray::fromRawData(data, N - 1);
}
-struct NegativeInteger { quint64 abs; };
-Q_DECLARE_METATYPE(NegativeInteger)
-
-struct SimpleType { uint8_t type; };
-Q_DECLARE_METATYPE(SimpleType)
-
-struct Float16Standin { uint16_t val; };
-Q_DECLARE_METATYPE(Float16Standin)
-
-struct Tag { CborTag tag; QVariant tagged; };
-Q_DECLARE_METATYPE(Tag)
-
template <typename... Args>
QVariant make_list(const Args &... args)
{
return QVariantList{args...};
}
-typedef QVector<QPair<QVariant, QVariant>> Map;
-Q_DECLARE_METATYPE(Map)
QVariant make_map(const std::initializer_list<QPair<QVariant, QVariant>> &list)
{
return QVariant::fromValue(Map(list));
}
-struct IndeterminateLengthArray : QVariantList { using QVariantList::QVariantList; };
-struct IndeterminateLengthMap : Map { using Map::Map; };
-Q_DECLARE_METATYPE(IndeterminateLengthArray)
-Q_DECLARE_METATYPE(IndeterminateLengthMap)
-
QVariant make_ilarray(const std::initializer_list<QVariant> &list)
{
return QVariant::fromValue(IndeterminateLengthArray(list));
@@ -239,9 +242,9 @@ void addFixedData()
QTest::newRow("0.f16") << raw("\xf9\0\0") << QVariant::fromValue(qfloat16(0));
QTest::newRow("-1.f16") << raw("\xf9\xbc\0") << QVariant::fromValue(qfloat16(-1));
QTest::newRow("1.5f16") << raw("\xf9\x3e\0") << QVariant::fromValue(qfloat16(1.5));
- QTest::newRow("nan_f16") << raw("\xf9\x7e\0") << QVariant::fromValue<qfloat16>(myNaNf());
- QTest::newRow("-inf_f16") << raw("\xf9\xfc\0") << QVariant::fromValue<qfloat16>(myNInff());
- QTest::newRow("+inf_f16") << raw("\xf9\x7c\0") << QVariant::fromValue<qfloat16>(myInff());
+ QTest::newRow("nan_f16") << raw("\xf9\x7e\0") << QVariant::fromValue<qfloat16>(qfloat16(myNaNf()));
+ QTest::newRow("-inf_f16") << raw("\xf9\xfc\0") << QVariant::fromValue<qfloat16>(qfloat16(myNInff()));
+ QTest::newRow("+inf_f16") << raw("\xf9\x7c\0") << QVariant::fromValue<qfloat16>(qfloat16(myInff()));
#endif
QTest::newRow("0.f") << raw("\xfa\0\0\0\0") << QVariant::fromValue(0.f);
@@ -343,4 +346,4 @@ void addArraysAndMaps()
QTest::newRow("array-1(map)") << raw("\x81\xc1\xa0") << make_list(QVariant::fromValue(Tag{1, make_map({})}));
QTest::newRow("map-1(2):3(4)") << raw("\xa1\xc1\2\xc3\4") << make_map({{QVariant::fromValue(Tag{1, 2}), QVariant::fromValue(Tag{3, 4})}});
}
-
+} // namespace
diff --git a/src/3rdparty/tinycbor/tests/encoder/encoder.pro b/src/3rdparty/tinycbor/tests/encoder/encoder.pro
deleted file mode 100644
index 62d9b7e409..0000000000
--- a/src/3rdparty/tinycbor/tests/encoder/encoder.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-SOURCES += tst_encoder.cpp
-
-CONFIG += testcase parallel_test c++11
-QT = core testlib
-
-INCLUDEPATH += ../../src
-msvc: POST_TARGETDEPS = ../../lib/tinycbor.lib
-else: POST_TARGETDEPS += ../../lib/libtinycbor.a
-LIBS += $$POST_TARGETDEPS
diff --git a/src/3rdparty/tinycbor/tests/encoder/tst_encoder.cpp b/src/3rdparty/tinycbor/tests/encoder/tst_encoder.cpp
index 458f55eb10..61ce9c995c 100644
--- a/src/3rdparty/tinycbor/tests/encoder/tst_encoder.cpp
+++ b/src/3rdparty/tinycbor/tests/encoder/tst_encoder.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
@@ -29,6 +29,19 @@
#include <qfloat16.h>
#endif
+#include <utility>
+namespace t17 {
+#ifdef __cpp_lib_as_const
+ using std::as_const;
+#else
+ template <typename T>
+ constexpr typename std::add_const<T>::type &as_const(T &t) noexcept { return t; }
+ // prevent rvalue arguments:
+ template <typename T>
+ void as_const(const T &&) = delete;
+#endif // __cpp_lib_as_const
+} // namespace t17
+
Q_DECLARE_METATYPE(CborError)
namespace QTest {
template<> char *toString<CborError>(const CborError &err)
@@ -153,7 +166,7 @@ CborError encodeVariant(CborEncoder *encoder, const QVariant &v)
CborError err = cbor_encoder_create_array(encoder, &sub, len);
if (err && !isOomError(err))
return err;
- foreach (const QVariant &v2, list) {
+ for (const QVariant &v2 : t17::as_const(list)) {
err = static_cast<CborError>(err | encodeVariant(&sub, v2));
if (err && !isOomError(err))
return err;
diff --git a/src/3rdparty/tinycbor/tests/parser/data.cpp b/src/3rdparty/tinycbor/tests/parser/data.cpp
index 3523c32167..c99160ad31 100644
--- a/src/3rdparty/tinycbor/tests/parser/data.cpp
+++ b/src/3rdparty/tinycbor/tests/parser/data.cpp
@@ -1,9 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 Intel Corporation
+**
+** Permission is hereby granted, free of charge, to any person obtaining a copy
+** of this software and associated documentation files (the "Software"), to deal
+** in the Software without restriction, including without limitation the rights
+** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+** copies of the Software, and to permit persons to whom the Software is
+** furnished to do so, subject to the following conditions:
+**
+** The above copyright notice and this permission notice shall be included in
+** all copies or substantial portions of the Software.
+**
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+** THE SOFTWARE.
+**
+****************************************************************************/
+
#include <QtTest>
#include <limits>
#include <cbor.h>
Q_DECLARE_METATYPE(CborError)
+namespace {
+
template <size_t N> QByteArray raw(const char (&data)[N])
{
return QByteArray::fromRawData(data, N - 1);
@@ -484,6 +510,7 @@ void addValidationData(size_t minInvalid = ~size_t(0))
QTest::newRow("map-no-break1") << raw("\x81\xbf") << 0 << CborErrorUnexpectedEOF;
QTest::newRow("map-no-break2") << raw("\x81\xbf\0\0") << 0 << CborErrorUnexpectedEOF;
QTest::newRow("map-break-after-key") << raw("\x81\xbf\0\xff") << 0 << CborErrorUnexpectedBreak;
+ QTest::newRow("map-break-after-second-key") << raw("\x81\xbf\x64xyzw\x04\x00\xff") << 0 << CborErrorUnexpectedBreak;
QTest::newRow("map-break-after-value-tag") << raw("\x81\xbf\0\xc0\xff") << 0 << CborErrorUnexpectedBreak;
QTest::newRow("map-break-after-value-tag2") << raw("\x81\xbf\0\xd8\x20\xff") << 0 << CborErrorUnexpectedBreak;
@@ -580,3 +607,4 @@ void addValidationData(size_t minInvalid = ~size_t(0))
// This test technically tests the dumper, not the parser.
QTest::newRow("string-utf8-chunk-split") << raw("\x81\x7f\x61\xc2\x61\xa0\xff") << 0 << CborErrorInvalidUtf8TextString;
}
+} // namespace
diff --git a/src/3rdparty/tinycbor/tests/parser/parser.pro b/src/3rdparty/tinycbor/tests/parser/parser.pro
deleted file mode 100644
index a61291a9e4..0000000000
--- a/src/3rdparty/tinycbor/tests/parser/parser.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-SOURCES += tst_parser.cpp ../../src/cborparser.c
-
-CONFIG += testcase parallel_test c++11
-QT = core testlib
-DEFINES += CBOR_PARSER_MAX_RECURSIONS=16
-
-INCLUDEPATH += ../../src
-msvc: POST_TARGETDEPS = ../../lib/tinycbor.lib
-else: POST_TARGETDEPS += ../../lib/libtinycbor.a
-LIBS += $$POST_TARGETDEPS
diff --git a/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp b/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
index 2b10004faa..91a65a00ba 100644
--- a/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
+++ b/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
@@ -894,22 +894,44 @@ static void chunkedStringTest(const QByteArray &data, const QString &concatenate
err = cbor_value_calculate_string_length(&copy, &n);
QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
- QByteArray buffer(n, Qt::Uninitialized);
+ size_t nn = n;
+ QByteArray buffer(n + 1, Qt::Uninitialized);
+ QByteArray buffer2(n + 1, Qt::Uninitialized);
+ buffer[int(n)] = 0xff;
+ buffer2[int(n)] = 0xff;
QString formatted;
if (cbor_value_is_byte_string(&copy)) {
- err = cbor_value_copy_byte_string(&copy, (uint8_t *)buffer.data(), &n, nullptr);
+ err = cbor_value_copy_byte_string(&copy, (uint8_t *)buffer.data(), &nn, nullptr);
QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
- QCOMPARE(int(n), buffer.size());
+ QCOMPARE(nn, n);
- formatted = QString::fromLatin1("h'" + buffer.toHex() + '\'');
+ formatted = QString::fromLatin1("h'" + QByteArray::fromRawData(buffer.data(), n).toHex() + '\'');
+
+ // repeat by allowing the null termination
+ nn = n + 1;
+ err = cbor_value_copy_byte_string(&copy, (uint8_t *)buffer2.data(), &nn, nullptr);
} else {
err = cbor_value_copy_text_string(&copy, buffer.data(), &n, nullptr);
QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
- QCOMPARE(int(n), buffer.size());
+ QCOMPARE(nn, n);
formatted = '"' + QString::fromUtf8(buffer.data(), n) + '"';
+
+ // repeat by allowing the null termination
+ nn = n + 1;
+ err = cbor_value_copy_text_string(&copy, buffer2.data(), &nn, nullptr);
}
+ QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
QCOMPARE(formatted, concatenated);
+
+ // verify terminators
+ QCOMPARE(buffer.at(n), char(0xff));
+ QCOMPARE(buffer2.at(n), '\0');
+ QCOMPARE(nn, n);
+
+ buffer.truncate(n);
+ buffer2.truncate(n);
+ QCOMPARE(buffer2, buffer);
}
// confirm that the extra string we appended is still here
@@ -1340,6 +1362,24 @@ void tst_Parser::validation()
QCOMPARE(err2, expectedError);
QCOMPARE(err3, expectedError);
}
+
+ // see if we've got a map
+ if (QByteArray(QTest::currentDataTag()).startsWith("map")) {
+ w.init(data, uint32_t(flags)); // reinit
+ QVERIFY(cbor_value_is_array(&w.first));
+
+ CborValue map;
+ CborError err = cbor_value_enter_container(&w.first, &map);
+ if (err == CborNoError) {
+ QVERIFY(cbor_value_is_map(&map));
+ CborValue element;
+ err = cbor_value_map_find_value(&map, "foobar", &element);
+ if (err == CborNoError)
+ QVERIFY(!cbor_value_is_valid(&element));
+ }
+
+ QCOMPARE(err, expectedError);
+ }
}
void tst_Parser::strictValidation_data()