Nits (#294)
- makefile dependency
- makefile install
- long lines
- TODO's
- #ifdef test fan out
* TODO's, test fan out, long lines...
* Fix test fan out problem
* More todo's, Makefile...
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/Makefile b/Makefile
index ff12907..206c440 100644
--- a/Makefile
+++ b/Makefile
@@ -34,9 +34,15 @@
src/ieee754.o \
src/qcbor_err_to_str.o
-TEST_OBJ=test/UsefulBuf_Tests.o test/qcbor_encode_tests.o \
- test/qcbor_decode_tests.o test/run_tests.o \
- test/float_tests.o test/half_to_double_from_rfc7049.o example.o tag-examples.o ub-example.o
+TEST_OBJ=test/UsefulBuf_Tests.o \
+ test/qcbor_encode_tests.o \
+ test/qcbor_decode_tests.o \
+ test/run_tests.o \
+ test/float_tests.o \
+ test/half_to_double_from_rfc7049.o \
+ example.o \
+ tag-examples.o \
+ ub-example.o
.PHONY: all so install uninstall clean warn
@@ -65,7 +71,9 @@
PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h \
inc/qcbor/qcbor_private.h \
inc/qcbor/qcbor_common.h \
- inc/qcbor/qcbor_encode.h \
+ inc/qcbor/qcbor_main_encode.h \
+ inc/qcbor/qcbor_number_encode.h \
+ inc/qcbor/qcbor_tag_encode.h \
inc/qcbor/qcbor_decode.h \
inc/qcbor/qcbor_main_decode.h \
inc/qcbor/qcbor_spiffy_decode.h \
@@ -74,11 +82,18 @@
src/UsefulBuf.o: inc/qcbor/UsefulBuf.h
-src/qcbor_encode.o: inc/qcbor/UsefulBuf.h \
- inc/qcbor/qcbor_private.h \
- inc/qcbor/qcbor_common.h \
- inc/qcbor/qcbor_encode.h \
- src/ieee754.h
+src/qcbor_main_encode.o: inc/qcbor/UsefulBuf.h \
+ inc/qcbor/qcbor_private.h \
+ inc/qcbor/qcbor_common.h \
+ inc/qcbor/qcbor_main_encode.h
+
+src/qcbor_tag_encode.o: inc/qcbor/UsefulBuf.h \
+ inc/qcbor/qcbor_private.h \
+ inc/qcbor/qcbor_common.h \
+ inc/qcbor/qcbor_main_encode.h \
+ inc/qcbor/qcbor_number_encode.h \
+ inc/qcbor/qcbor_tag_encode.h \
+ src/ieee754.h
src/qcbor_main_decode.o: inc/qcbor/UsefulBuf.h \
inc/qcbor/qcbor_private.h \
@@ -97,6 +112,14 @@
src/decode_nesting.h \
inc/qcbor/qcbor_tag_decode.h
+src/qcbor_spiffy_decode.o: inc/qcbor/UsefulBuf.h \
+ inc/qcbor/qcbor_private.h \
+ inc/qcbor/qcbor_common.h \
+ inc/qcbor/qcbor_main_decode.h \
+ inc/qcbor/qcbor_spiffy_decode.h \
+ src/decode_nesting.h \
+ inc/qcbor/qcbor_tag_decode.h
+
src/qcbor_number_decode.o: inc/qcbor/UsefulBuf.h \
inc/qcbor/qcbor_private.h \
inc/qcbor/qcbor_common.h \
@@ -136,8 +159,16 @@
install -m 644 inc/qcbor/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor
install -m 644 inc/qcbor/qcbor_private.h $(DESTDIR)$(PREFIX)/include/qcbor
install -m 644 inc/qcbor/qcbor_common.h $(DESTDIR)$(PREFIX)/include/qcbor
+ install -m 644 inc/qcbor/qcbor_main_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
+ install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
+ install -m 644 inc/qcbor/qcbor_number_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
+ install -m 644 inc/qcbor/qcbor_tag_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
+ install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
+ install -m 644 inc/qcbor/qcbor_main_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
+ install -m 644 inc/qcbor/qcbor_number_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
+ install -m 644 inc/qcbor/qcbor_tag_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
install -m 644 inc/qcbor/qcbor_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
install -m 644 inc/qcbor/UsefulBuf.h $(DESTDIR)$(PREFIX)/include/qcbor
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index b6fbdd1..cf4fb0a 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -36,7 +36,6 @@
#ifndef qcbor_common_h
#define qcbor_common_h
-
#ifdef __cplusplus
extern "C" {
#if 0
@@ -64,7 +63,7 @@
#define QCBOR_VERSION_MINOR 0
#define QCBOR_VERSION_PATCH 0
-
+/* This is an alpha (not ready for commercial use) release of 2.0.0 */
/**
* This define indicates a version of QCBOR that supports spiffy
@@ -554,9 +553,7 @@
*/
QCBOR_ERR_NOT_PREFERRED = 79,
- /** Trying to encode something that is discouraged (e.g., 65-bit
- * negative integer) without allowing it by calling
- * QCBOREncode_Allow() */
+ /** Trying to do something that is not allowed. */
QCBOR_ERR_NOT_ALLOWED = 80,
/** QCBORDecode_EnterBstrWrapped() cannot be used on
diff --git a/inc/qcbor/qcbor_main_decode.h b/inc/qcbor/qcbor_main_decode.h
index 8f3e487..1efefef 100644
--- a/inc/qcbor/qcbor_main_decode.h
+++ b/inc/qcbor/qcbor_main_decode.h
@@ -399,24 +399,24 @@
/** A floating-point number made of base-2 exponent and positive big
* number mantissa. See @ref expAndMantissa and
* QCBOREncode_AddTBigFloatBigMantissa(). */
-// TODO: rename to BIGMANTISSA?
+#define QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA 18
#define QCBOR_TYPE_BIGFLOAT_POS_BIGNUM 18
/** A floating-point number made of base-2 exponent and negative big
* number mantissa. See @ref expAndMantissa and
* QCBOREncode_AddTBigFloatBigMantissa(). */
+#define QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA 19
#define QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM 19
/** A floating-point number made of base-2 exponent and positive big
* number mantissa. See @ref expAndMantissa and
* QCBOREncode_AddTBigFloatBigMantissa(). */
-// TODO: rename to U64MANTISSA
-#define QCBOR_TYPE_BIGFLOAT_POS_U64 82
+#define QCBOR_TYPE_BIGFLOAT_POS_U64MANTISSA 82
/** A floating-point number made of base-2 exponent and negative big
* number mantissa. See @ref expAndMantissa and
* QCBOREncode_AddTBigFloatBigMantissa(). */
-#define QCBOR_TYPE_BIGFLOAT_NEG_U64 83
+#define QCBOR_TYPE_BIGFLOAT_NEG_U64MANTISSA 83
/** Type for the simple value false. */
#define QCBOR_TYPE_FALSE 20
@@ -857,6 +857,7 @@
bool bAllStrings);
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
/**
* @brief Sets up a custom string allocator for indefinite-length strings
*
@@ -890,12 +891,13 @@
* @c uLabelAlloc @c == @c 1 in @ref QCBORItem. Note this is in a
* separate GitHub repository.
*/
-void
+static void
QCBORDecode_SetUpAllocator(QCBORDecodeContext *pCtx,
QCBORStringAllocate pfAllocateFunction,
void *pAllocateContext,
bool bAllStrings);
+#endif /* ! QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
/**
* @brief Get the next item (integer, byte string, array...) in the
@@ -921,7 +923,8 @@
* - The label for an item in a map, which may be a text or byte string
* or an integer.
*
- * - When @ref QCBOR_DECODE_ALLOW_UNPROCESSED_TAG_NUMBERS is set, unprocessed tag numbers.
+ * - When @ref QCBOR_DECODE_ALLOW_UNPROCESSED_TAG_NUMBERS is set,
+ * unprocessed tag numbers.
*
* See @ref QCBORItem for all the details about what is returned.
*
@@ -1222,7 +1225,7 @@
* use. Because of this, It can't be called multiple times like
* QCBORDecode_PartialFinish().
*
- * Some CBOR protocols use a CBOR sequence defined in
+ * Some CBOR protocols use a CBOR sequence defined in
* [RFC 8742](https://tools.ietf.org/html/rfc8742).
* A CBOR sequence typically
* doesn't start out with a map or an array. The end of the CBOR is
@@ -1439,22 +1442,6 @@
QCBORDecode_Private_GetNextTagContent(QCBORDecodeContext *pMe,
QCBORItem *pDecodedItem);
-/** @private Semi-private function. See qcbor_decode.c */
-void
-QCBORDecode_Private_GetItemInMapNoCheckSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uQcborType,
- QCBORItem *pItem,
- size_t *puOffset);
-
-/** @private Semi-private function. See qcbor_decode.c */ // TODO: this a next are spiffy
-void
-QCBORDecode_Private_GetItemInMapNoCheckN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uQcborType,
- QCBORItem *pItem,
- size_t *puOffset);
-
/** @private Semi-private function. See qcbor_decode.c */
uint64_t
@@ -1481,6 +1468,19 @@
bool bMarkEnd,
bool *pbBreak);
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
+static inline void
+QCBORDecode_SetUpAllocator(QCBORDecodeContext *pMe,
+ QCBORStringAllocate pfAllocateFunction,
+ void *pAllocateContext,
+ bool bAllStrings)
+{
+ pMe->StringAllocator.pfAllocator = pfAllocateFunction;
+ pMe->StringAllocator.pAllocateCxt = pAllocateContext;
+ pMe->bStringAllocateAll = bAllStrings;
+}
+#endif /* ! QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+
static inline uint32_t
QCBORDecode_Tell(QCBORDecodeContext *pMe)
@@ -1548,7 +1548,9 @@
QCBORDecode_Private_SaveTagNumbers(QCBORDecodeContext *pMe, const QCBORItem *pItem)
{
#ifndef QCBOR_DISABLE_TAGS
- memcpy(pMe->auLastTagNumbers, pItem->auTagNumbers, sizeof(pItem->auTagNumbers));
+ memcpy(pMe->auLastTagNumbers,
+ pItem->auTagNumbers,
+ sizeof(pItem->auTagNumbers));
#else /* ! QCBOR_DISABLE_TAGS */
(void)pMe;
(void)pItem;
diff --git a/inc/qcbor/qcbor_main_encode.h b/inc/qcbor/qcbor_main_encode.h
index a87f9a0..7e148a2 100644
--- a/inc/qcbor/qcbor_main_encode.h
+++ b/inc/qcbor/qcbor_main_encode.h
@@ -163,10 +163,10 @@
*/
QCBOR_ENCODE_CONFIG_SORT = 0x01,
- /** By default QCBOR will error out when trying to encode a double
- * or float NaN that has a payload because NaN payloads are not
- * very interoperable. With this set, NaN payloads can be encoded.
- *
+ /** By default QCBOR will error with @ref QCBOR_ERR_NOT_ALLOWED
+ * when trying to encode a double or float NaN that has a payload
+ * because NaN payloads are not very interoperable. With this set,
+ * NaN payloads can be encoded.
*/
QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD = 0x02,
@@ -192,9 +192,9 @@
QCBOR_ENCODE_CONFIG_DISALLOW_INDEFINITE_LENGTHS = 0x08,
/** This disallows non-preferred floating number encoding,
- QCBOREncode_AddFloatNoPreferred() and
- QCBOREncode_AddDoubleNoPreferred(). It is not possible to disable
- preferred serialization of type 0 and type 1 integers in QCBOR. */
+ * QCBOREncode_AddFloatNoPreferred() and
+ * QCBOREncode_AddDoubleNoPreferred(). It is not possible to disable
+ * preferred serialization of type 0 and type 1 integers in QCBOR. */
QCBOR_ENCODE_CONFIG_DISALLOW_NON_PREFERRED_NUMBERS = 0x10,
/**
@@ -402,9 +402,8 @@
*
* This is the same as QCBOREncode_Config() except it can't
* configure anything to do with map sorting. That includes
- * both @ref CDE and @ref dCBOR.
- *
- *
+ * both @ref CDE and @ref dCBOR. @ref QCBOR_ERR_NOT_ALLOWED
+ * is returned if trying to configure map sorting.
*/
static void
QCBOREncode_ConfigReduced(QCBOREncodeContext *pCtx, enum QCBOREncodeConfig uConfig);
@@ -911,7 +910,7 @@
* though map items are not all the same size because it always swaps
* adjacent items.
*/
-void
+void
QCBOREncode_CloseAndSortMap(QCBOREncodeContext *pCtx);
/** See QCBOREncode_CloseAndSortMapIndef(). */
@@ -1449,6 +1448,10 @@
static inline void
QCBOREncode_Config(QCBOREncodeContext *pMe, enum QCBOREncodeConfig uConfig)
{
+ /* The close function is made a function pointer as a way to avoid
+ * linking the proportionately large chunk of code for sorting
+ * maps unless explicitly requested. QCBOREncode_CloseAndSortMap()
+ * doesn't get linked unless this function is called. */
if(uConfig & QCBOR_ENCODE_CONFIG_SORT) {
pMe->pfnCloseMap = QCBOREncode_CloseAndSortMap;
} else {
@@ -1462,7 +1465,7 @@
QCBOREncode_ConfigReduced(QCBOREncodeContext *pMe, enum QCBOREncodeConfig uConfig)
{
if(uConfig & QCBOR_ENCODE_CONFIG_SORT) {
- pMe->uError = 99;
+ pMe->uError = QCBOR_ERR_NOT_ALLOWED;
} else {
pMe->uConfigFlags = (int)uConfig;
}
diff --git a/inc/qcbor/qcbor_number_encode.h b/inc/qcbor/qcbor_number_encode.h
index 457e708..95d224f 100644
--- a/inc/qcbor/qcbor_number_encode.h
+++ b/inc/qcbor/qcbor_number_encode.h
@@ -156,7 +156,7 @@
* represent the value. For example, CBOR always encodes the value 0
* as one byte, 0x00. The representation as 0x00 includes
* identification of the type as an integer too as the major type for
- * an integer is 0. See
+ * an integer is 0. See
* [RFC 8949 Appendix A](https://www.rfc-editor.org/rfc/rfc8949.html#section-appendix.a)
* for more examples of CBOR encoding. This compact encoding is
* preferred serialization CBOR as per
@@ -497,7 +497,7 @@
* byte order).
*
* This encodes CBOR tag numbers 2 and 3, positive and negative big
- * numbers, as defined in
+ * numbers, as defined in
* [RFC 8949 section 3.4.3](https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.3).
*
* This performs the offset of one required when encoding negative
@@ -720,12 +720,15 @@
* mantissa is a big number (See QCBOREncode_AddTBignumber())
* allowing for arbitrarily large precision.
*
- * Preferred serialization of the big number is used. This means it may be converted to
- * a type 0 or type 1 integers making the result the same as QCBOREncode_AddTDecimalFraction().
- * This also offsets negative big numbers by one.
+ * Preferred serialization of the big number is used. This means it
+ * may be converted to a type 0 or type 1 integers making the result
+ * the same as QCBOREncode_AddTDecimalFraction(). This also offsets
+ * negative big numbers by one.
*
- * If you want the big number to be copied straight through without the conversion to type 0
- * and 1 integers and without the offset of 1 (and much smaller objet code) use QCBOREncode_AddTBigFloatBigMantissaRaw().
+ * If you want the big number to be copied straight through without
+ * the conversion to type 0 and 1 integers and without the offset of 1
+ * (and much smaller objet code) use
+ * QCBOREncode_AddTBigFloatBigMantissaRaw().
*
* See @ref expAndMantissa for decoded representation.
*/
diff --git a/inc/qcbor/qcbor_private.h b/inc/qcbor/qcbor_private.h
index caf346f..4655a43 100644
--- a/inc/qcbor/qcbor_private.h
+++ b/inc/qcbor/qcbor_private.h
@@ -235,7 +235,7 @@
int uConfigFlags; /* enum QCBOREncodeConfig */
void (*pfnCloseMap)(QCBORPrivateEncodeContext *); /* Use of function
- * pointer explained in TODO: */
+ * pointer explained in QCBOREncode_Config() */
QCBORTrackNesting nesting; /* Keep track of array and map nesting */
};
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index f79c256..6a5ba95 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -510,7 +510,12 @@
/**
* @brief Position traversal cursor by map label.
*
- * TODO: finish this documentation
+ * @param[in] pCtx The decode context.
+ * @param[in] nLabel The map label to seek too.
+ *
+ * On failure, such as map label not found, this sets the last error
+ * and doesn't change the traversal cursor. On success the traversal
+ * cursor is moved to the map label item.
*/
void
QCBORDecode_SeekToLabelN(QCBORDecodeContext *pCtx, int64_t nLabel);
@@ -519,7 +524,12 @@
/**
* @brief Position traversal cursor by map label.
*
- * TODO: finish this documentation
+ * @param[in] pCtx The decode context.
+ * @param[in] nLabel The map label to seek too.
+ *
+ * On failure, such as map label not found, this sets the last error
+ * and doesn't change the traversal cursor. On success the traversal
+ * cursor is moved to the map label item.
*/
void
QCBORDecode_SeekToLabelSZ(QCBORDecodeContext *pMe, const char *szLabel);
@@ -857,6 +867,21 @@
const uint32_t uEndOffset);
+/** @private Semi-private function. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetItemInMapNoCheckSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uQcborType,
+ QCBORItem *pItem,
+ size_t *puOffset);
+
+/** @private Semi-private function. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetItemInMapNoCheckN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uQcborType,
+ QCBORItem *pItem,
+ size_t *puOffset);
static inline void
diff --git a/src/qcbor_main_decode.c b/src/qcbor_main_decode.c
index 752d8d5..68fa1b0 100644
--- a/src/qcbor_main_decode.c
+++ b/src/qcbor_main_decode.c
@@ -37,7 +37,6 @@
#include "ieee754.h" /* Does not use math.h */
#include "decode_nesting.h"
-// TODO: Reduce the circular dependency here
#include "qcbor/qcbor_tag_decode.h"
@@ -214,27 +213,6 @@
-#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
-
-// TODO: inline this; #ifdef out the prototype too
-/* Public function; see qcbor_main_decode.h */
-void
-QCBORDecode_SetUpAllocator(QCBORDecodeContext *pMe,
- QCBORStringAllocate pfAllocateFunction,
- void *pAllocateContext,
- bool bAllStrings)
-{
- pMe->StringAllocator.pfAllocator = pfAllocateFunction;
- pMe->StringAllocator.pAllocateCxt = pAllocateContext;
- pMe->bStringAllocateAll = bAllStrings;
-}
-#endif /* ! QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
-
-
-
-
-
-
/*
* Decoding items is done in six layers, one calling the next one
* down. If a layer has no work to do for a particular item, it
@@ -783,16 +761,19 @@
}
#else /* ! QCBOR_DISABLE_DECODE_CONFORMANCE && ! QCBOR_DISABLE_PREFERRED_FLOAT */
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
static QCBORError
QCBORDecode_Private_HalfConformance(const double d, const QCBORDecodeMode uConfigFlags)
{
- (void)d;
- if(uConfigFlags & (QCBOR_DECODE_ONLY_REDUCED_FLOATS | QCBOR_DECODE_ONLY_PREFERRED_NUMBERS)) {
- return QCBOR_ERR_CANT_CHECK_FLOAT_CONFORMANCE;
- } else {
- return QCBOR_SUCCESS;
- }
+ (void)d;
+ if(uConfigFlags & (QCBOR_DECODE_ONLY_REDUCED_FLOATS | QCBOR_DECODE_ONLY_PREFERRED_NUMBERS)) {
+ return QCBOR_ERR_CANT_CHECK_FLOAT_CONFORMANCE;
+ } else {
+ return QCBOR_SUCCESS;
+ }
}
+#endif
+
static QCBORError
QCBORDecode_Private_SingleConformance(const float f, const QCBORDecodeMode uConfigFlags)
diff --git a/src/qcbor_number_decode.c b/src/qcbor_number_decode.c
index 34896e4..571c1ba 100644
--- a/src/qcbor_number_decode.c
+++ b/src/qcbor_number_decode.c
@@ -1262,7 +1262,7 @@
}
break;
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA:
if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
int64_t nMantissa;
QCBORError uErr;
@@ -1279,7 +1279,7 @@
}
break;
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA:
if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
int64_t nMantissa;
QCBORError uErr;
@@ -1477,7 +1477,7 @@
}
break;
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA:
if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
uint64_t uMantissa;
QCBORError uErr;
@@ -1495,7 +1495,7 @@
}
break;
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA:
if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
} else {
@@ -1682,7 +1682,7 @@
}
break;
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA:
if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
double dMantissa = QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
*pdValue = dMantissa * exp2((double)pItem->val.expAndMantissa.nExponent);
@@ -1691,7 +1691,7 @@
}
break;
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA:
if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
double dMantissa = -1-QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
*pdValue = dMantissa * exp2((double)pItem->val.expAndMantissa.nExponent);
@@ -1993,7 +1993,8 @@
} else if(uType == QCBOR_TYPE_INT64) {
/* Offset of 1 for negative numbers already performed */
*pbIsNegative = Item.val.int64 < 0;
- *pBigNumber = QCBORDecode_Private_UIntToBigNumber((uint64_t)(*pbIsNegative ? -Item.val.int64 : Item.val.int64), BigNumberBuf);
+ const uint64_t uIntTmp = (uint64_t)(*pbIsNegative ? -Item.val.int64 : Item.val.int64);
+ *pBigNumber = QCBORDecode_Private_UIntToBigNumber(uIntTmp, BigNumberBuf);
} else if(uType == QCBOR_TYPE_65BIT_NEG_INT) {
/* Offset of 1 for negative numbers NOT already performed */
*pbIsNegative = true;
@@ -2188,7 +2189,13 @@
size_t uOffset;
QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
+ QCBORDecode_Private_BigNumberNoPreferredMain(pMe,
+ uTagRequirement,
+ &Item,
+ uOffset,
+ BigNumberBuf,
+ pBigNumber,
+ pbIsNegative);
}
/* Public function, see qcbor/qcbor_number_decode.h */
@@ -2204,7 +2211,13 @@
size_t uOffset;
QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
+ QCBORDecode_Private_BigNumberNoPreferredMain(pMe,
+ uTagRequirement,
+ &Item,
+ uOffset,
+ BigNumberBuf,
+ pBigNumber,
+ pbIsNegative);
}
@@ -2221,7 +2234,13 @@
size_t uOffset;
QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
+ QCBORDecode_Private_BigNumberNoPreferredMain(pMe,
+ uTagRequirement,
+ &Item,
+ uOffset,
+ BigNumberBuf,
+ pBigNumber,
+ pbIsNegative);
}
@@ -2291,41 +2310,6 @@
#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
-
-// TODO: relocate these notes?
-/* Some notes from the work to disable tags.
- * Some are out of date since tag refactoring.
- *
- * The API for big floats and decimal fractions seems good.
- * If there's any issue with it it's that the code size to
- * implement is a bit large because of the conversion
- * to/from int and bignum that is required. There is no API
- * that doesn't do the conversion so dead stripping will never
- * leave that code out.
- *
- * The implementation itself seems correct, but not as clean
- * and neat as it could be. It could probably be smaller too.
- *
- * The implementation has three main parts / functions
- * - The decoding of the array of two
- * - All the tag and type checking for the various API functions
- * - Conversion to/from bignum and int
- *
- * The type checking seems like it wastes the most code for
- * what it needs to do.
- *
- * The inlining for the conversion is probably making the
- * overall code base larger.
- *
- * The tests cases could be organized a lot better and be
- * more thorough.
- *
- * Seems also like there could be more common code in the
- * first tier part of the public API. Some functions only
- * vary by a TagSpec.
- */
-
-
static const uint8_t QCBORDecode_Private_DecimalFractionTypes[] = {
QCBOR_TYPE_DECIMAL_FRACTION,
QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM,
@@ -2336,10 +2320,10 @@
static const uint8_t QCBORDecode_Private_BigFloatTypes[] = {
QCBOR_TYPE_BIGFLOAT,
- QCBOR_TYPE_BIGFLOAT_POS_BIGNUM,
- QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM,
- QCBOR_TYPE_BIGFLOAT_POS_U64,
- QCBOR_TYPE_BIGFLOAT_NEG_U64,
+ QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA,
+ QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA,
+ QCBOR_TYPE_BIGFLOAT_POS_U64MANTISSA,
+ QCBOR_TYPE_BIGFLOAT_NEG_U64MANTISSA,
QCBOR_TYPE_NONE};
/**
@@ -2368,7 +2352,7 @@
*/
static void
QCBORDecode_Private_ExpIntMantissaMain(QCBORDecodeContext *pMe,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const uint64_t uTagNumber,
const size_t uOffset,
QCBORItem *pItem,
@@ -2390,7 +2374,7 @@
QCBORDecode_Private_ProcessTagItem(pMe,
pItem,
- uTagRequirement,
+ uTagReq,
qTypes,
uTagNumber,
QCBORDecode_ExpMantissaTagCB,
@@ -2412,21 +2396,21 @@
#ifndef QCBOR_DISABLE_TAGS
/* If tags are disabled, mantissas can never be big nums */
case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA:
*pnExponent = pItem->val.expAndMantissa.nExponent;
uErr = QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, pnMantissa);
break;
case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA:
*pnExponent = pItem->val.expAndMantissa.nExponent;
uErr = QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, pnMantissa);
break;
#endif /* ! QCBOR_DISABLE_TAGS */
- case QCBOR_TYPE_BIGFLOAT_NEG_U64:
+ case QCBOR_TYPE_BIGFLOAT_NEG_U64MANTISSA:
case QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64:
- case QCBOR_TYPE_BIGFLOAT_POS_U64:
+ case QCBOR_TYPE_BIGFLOAT_POS_U64MANTISSA:
case QCBOR_TYPE_DECIMAL_FRACTION_POS_U64:
uErr = QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
break;
@@ -2440,7 +2424,7 @@
static void
QCBORDecode_Private_ExpBigMantissaRawMain(QCBORDecodeContext *pMe,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const uint64_t uTagNumber,
const size_t uOffset,
QCBORItem *pItem,
@@ -2465,7 +2449,7 @@
QCBORDecode_Private_ProcessTagItem(pMe,
pItem,
- uTagRequirement,
+ uTagReq,
qTypes,
uTagNumber,
QCBORDecode_ExpMantissaTagCB,
@@ -2506,14 +2490,14 @@
#ifndef QCBOR_DISABLE_TAGS
/* If tags are disabled, mantissas can never be big nums */
case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA:
*pnExponent = pItem->val.expAndMantissa.nExponent;
*pMantissa = pItem->val.expAndMantissa.Mantissa.bigNum;
*pbIsNegative = false;
break;
case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA:
*pnExponent = pItem->val.expAndMantissa.nExponent;
*pMantissa = pItem->val.expAndMantissa.Mantissa.bigNum;
*pbIsNegative = true;
@@ -2548,7 +2532,7 @@
*/
static void
QCBORDecode_Private_ExpBigMantissaMain(QCBORDecodeContext *pMe,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const uint64_t uTagNumber,
const size_t uOffset,
QCBORItem *pItem,
@@ -2573,7 +2557,7 @@
QCBORDecode_Private_ProcessTagItem(pMe,
pItem,
- uTagRequirement,
+ uTagReq,
qTypes,
uTagNumber,
QCBORDecode_ExpMantissaTagCB,
@@ -2594,13 +2578,13 @@
break;
case QCBOR_TYPE_DECIMAL_FRACTION_POS_U64:
- case QCBOR_TYPE_BIGFLOAT_POS_U64:
+ case QCBOR_TYPE_BIGFLOAT_POS_U64MANTISSA:
TempMantissa.uDataType = QCBOR_TYPE_UINT64;
TempMantissa.val.uint64 = pItem->val.expAndMantissa.Mantissa.uInt;
break;
case QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64:
- case QCBOR_TYPE_BIGFLOAT_NEG_U64:
+ case QCBOR_TYPE_BIGFLOAT_NEG_U64MANTISSA:
TempMantissa.uDataType = QCBOR_TYPE_65BIT_NEG_INT;
TempMantissa.val.uint64 = pItem->val.expAndMantissa.Mantissa.uInt;
break;
@@ -2608,14 +2592,14 @@
#ifndef QCBOR_DISABLE_TAGS
/* If tags are disabled, mantissas can never be big nums */
case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA:
TempMantissa.uDataType = QCBOR_TYPE_BYTE_STRING;
TempMantissa.val.bigNum = pItem->val.expAndMantissa.Mantissa.bigNum;
*pbIsNegative = false;
break;
case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA:
TempMantissa.uDataType = QCBOR_TYPE_BYTE_STRING;
TempMantissa.val.bigNum = pItem->val.expAndMantissa.Mantissa.bigNum;
*pbIsNegative = true;
@@ -2655,7 +2639,7 @@
void
QCBORDecode_GetTDecimalFractionInMapN(QCBORDecodeContext *pMe,
const int64_t nLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
int64_t *pnMantissa,
int64_t *pnExponent)
{
@@ -2664,7 +2648,7 @@
QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpIntMantissaMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_DECIMAL_FRACTION,
uOffset,
&Item,
@@ -2678,7 +2662,7 @@
void
QCBORDecode_GetTDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
const char *szLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
int64_t *pnMantissa,
int64_t *pnExponent)
{
@@ -2687,7 +2671,7 @@
QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpIntMantissaMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_DECIMAL_FRACTION,
uOffset,
&Item,
@@ -2699,7 +2683,7 @@
/* Public function, see qcbor/qcbor_number_decode.h */
void
QCBORDecode_GetTDecimalFractionBigMantissa(QCBORDecodeContext *pMe,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf MantissaBuffer,
UsefulBufC *pMantissa,
bool *pbMantissaIsNegative,
@@ -2710,7 +2694,7 @@
QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_DECIMAL_FRACTION,
uOffset,
&Item,
@@ -2725,7 +2709,7 @@
void
QCBORDecode_GetTDecimalFractionBigMantissaInMapN(QCBORDecodeContext *pMe,
const int64_t nLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf BufferForMantissa,
UsefulBufC *pMantissa,
bool *pbIsNegative,
@@ -2736,7 +2720,7 @@
QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_DECIMAL_FRACTION,
uOffset,
&Item,
@@ -2751,7 +2735,7 @@
void
QCBORDecode_GetTDecimalFractionBigMantissaInMapSZ(QCBORDecodeContext *pMe,
const char *szLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf BufferForMantissa,
UsefulBufC *pMantissa,
bool *pbIsNegative,
@@ -2762,7 +2746,7 @@
QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_DECIMAL_FRACTION,
uOffset,
&Item,
@@ -2775,7 +2759,7 @@
/* Public function, see qcbor/qcbor_number_decode.h */
void
QCBORDecode_GetTDecimalFractionBigMantissaRaw(QCBORDecodeContext *pMe,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf MantissaBuffer,
UsefulBufC *pMantissa,
bool *pbMantissaIsNegative,
@@ -2786,7 +2770,7 @@
QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_DECIMAL_FRACTION,
uOffset,
&Item,
@@ -2801,7 +2785,7 @@
void
QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN(QCBORDecodeContext *pMe,
const int64_t nLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf BufferForMantissa,
UsefulBufC *pMantissa,
bool *pbIsNegative,
@@ -2812,7 +2796,7 @@
QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_DECIMAL_FRACTION,
uOffset,
&Item,
@@ -2827,7 +2811,7 @@
void
QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ(QCBORDecodeContext *pMe,
const char *szLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf BufferForMantissa,
UsefulBufC *pMantissa,
bool *pbIsNegative,
@@ -2838,7 +2822,7 @@
QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_DECIMAL_FRACTION,
uOffset,
&Item,
@@ -2917,7 +2901,7 @@
/* Public function, see qcbor/qcbor_number_decode.h */
void
QCBORDecode_GetTBigFloatBigMantissa(QCBORDecodeContext *pMe,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf MantissaBuffer,
UsefulBufC *pMantissa,
bool *pbMantissaIsNegative,
@@ -2928,7 +2912,7 @@
QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_BIGFLOAT,
uOffset,
&Item,
@@ -2944,7 +2928,7 @@
void
QCBORDecode_GetTBigFloatBigMantissaInMapN(QCBORDecodeContext *pMe,
const int64_t nLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf BufferForMantissa,
UsefulBufC *pMantissa,
bool *pbIsNegative,
@@ -2955,7 +2939,7 @@
QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_BIGFLOAT,
uOffset,
&Item,
@@ -2970,7 +2954,7 @@
void
QCBORDecode_GetTBigFloatBigMantissaInMapSZ(QCBORDecodeContext *pMe,
const char *szLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf BufferForMantissa,
UsefulBufC *pMantissa,
bool *pbIsNegative,
@@ -2981,7 +2965,7 @@
QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_BIGFLOAT,
uOffset,
&Item,
@@ -2995,7 +2979,7 @@
/* Public function, see qcbor/qcbor_number_decode.h */
void
QCBORDecode_GetTBigFloatBigMantissaRaw(QCBORDecodeContext *pMe,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf MantissaBuffer,
UsefulBufC *pMantissa,
bool *pbMantissaIsNegative,
@@ -3006,7 +2990,7 @@
QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_BIGFLOAT,
uOffset,
&Item,
@@ -3020,7 +3004,7 @@
void
QCBORDecode_GetTBigFloatBigMantissaRawInMapN(QCBORDecodeContext *pMe,
const int64_t nLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf BufferForMantissa,
UsefulBufC *pMantissa,
bool *pbIsNegative,
@@ -3031,7 +3015,7 @@
QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_BIGFLOAT,
uOffset,
&Item,
@@ -3046,7 +3030,7 @@
void
QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ(QCBORDecodeContext *pMe,
const char *szLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const UsefulBuf BufferForMantissa,
UsefulBufC *pMantissa,
bool *pbIsNegative,
@@ -3057,7 +3041,7 @@
QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
+ uTagReq,
CBOR_TAG_BIGFLOAT,
uOffset,
&Item,
diff --git a/src/qcbor_number_encode.c b/src/qcbor_number_encode.c
index 91ff289..e23c2d3 100644
--- a/src/qcbor_number_encode.c
+++ b/src/qcbor_number_encode.c
@@ -130,7 +130,9 @@
FloatResult = IEEE754_DoubleToSmaller(dNum, true, bNoNaNPayload);
- QCBOREncode_Private_AddType7(pMe, (uint8_t)FloatResult.uSize, FloatResult.uValue);
+ QCBOREncode_Private_AddType7(pMe,
+ (uint8_t)FloatResult.uSize,
+ FloatResult.uValue);
}
@@ -190,7 +192,9 @@
FloatResult = IEEE754_SingleToHalf(fNum, bNoNaNPayload);
- QCBOREncode_Private_AddType7(pMe, (uint8_t)FloatResult.uSize, FloatResult.uValue);
+ QCBOREncode_Private_AddType7(pMe,
+ (uint8_t)FloatResult.uSize,
+ FloatResult.uValue);
}
#endif /* ! QCBOR_DISABLE_PREFERRED_FLOAT */
@@ -418,7 +422,7 @@
if(bNegative) {
QCBOREncode_Private_AddTNegativeBigNumber(pMe, uTagRequirement, BigNumberNLZ);
} else {
- QCBOREncode_AddTBigNumberRaw(pMe, false, uTagRequirement, BigNumberNLZ);
+ QCBOREncode_AddTBigNumberRaw(pMe, false, uTagRequirement,BigNumberNLZ);
}
}
}
diff --git a/src/qcbor_spiffy_decode.c b/src/qcbor_spiffy_decode.c
index fcad613..1c13bdc 100644
--- a/src/qcbor_spiffy_decode.c
+++ b/src/qcbor_spiffy_decode.c
@@ -15,9 +15,6 @@
#include "qcbor/qcbor_main_decode.h"
#include "qcbor/qcbor_spiffy_decode.h"
-// TODO: see about removing these two includes
-#include "qcbor/qcbor_tag_decode.h"
-#include "ieee754.h" /* Does not use math.h */
#include "decode_nesting.h"
@@ -606,8 +603,6 @@
-
-
/**
* @brief Semi-private. Get pointer, length and item count of an array or map.
*
@@ -999,7 +994,6 @@
-
/**
* @brief Process simple type true and false, a boolean
*
diff --git a/src/qcbor_tag_decode.c b/src/qcbor_tag_decode.c
index 658ac10..c6dc17e 100644
--- a/src/qcbor_tag_decode.c
+++ b/src/qcbor_tag_decode.c
@@ -126,7 +126,10 @@
OneItemSeach[0].uDataType = QCBOR_TYPE_ANY;
OneItemSeach[1].uLabelType = QCBOR_TYPE_NONE; // Indicates end of array
- QCBORError uReturn = QCBORDecode_Private_MapSearch(pMe, OneItemSeach, &Info, NULL);
+ QCBORError uReturn = QCBORDecode_Private_MapSearch(pMe,
+ OneItemSeach,
+ &Info,
+ NULL);
uOffset = Info.uStartOffset;
@@ -289,13 +292,13 @@
const size_t uOffset,
const uint8_t *uQCBORTypes,
const uint64_t *uTagNumbers,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
bool *bTypeMatched)
{
const uint8_t *pTypeNum;
- const enum QCBORDecodeTagReq nTagReq = (enum QCBORDecodeTagReq)((int)uTagRequirement & ~QCBOR_TAG_REQUIREMENT_ALLOW_ADDITIONAL_TAGS);
-
+ const int nTagReqTmp = (int)uTagReq & ~QCBOR_TAG_REQUIREMENT_ALLOW_ADDITIONAL_TAGS;
+ const enum QCBORDecodeTagReq nTagReq = (enum QCBORDecodeTagReq)nTagReqTmp;
*bTypeMatched = false;
for(pTypeNum = uQCBORTypes; *pTypeNum != QCBOR_TYPE_NONE; pTypeNum++) {
@@ -338,7 +341,7 @@
}
/* Now check if there are extra tags and if there's an error in them */
- if(!(uTagRequirement & QCBOR_TAG_REQUIREMENT_ALLOW_ADDITIONAL_TAGS)) {
+ if(!(uTagReq & QCBOR_TAG_REQUIREMENT_ALLOW_ADDITIONAL_TAGS)) {
/* The flag to ignore extra is not set, so keep checking */
for(pTNum = uTagNumbers; *pTNum != CBOR_TAG_INVALID64; pTNum++) {
uErr = QCBORDecode_Private_Check1TagNumber(pMe, pItem, *pTNum, uOffset);
@@ -368,7 +371,7 @@
void
QCBORDecode_Private_ProcessTagItemMulti(QCBORDecodeContext *pMe,
QCBORItem *pItem,
- enum QCBORDecodeTagReq uTagRequirement,
+ enum QCBORDecodeTagReq uTagReq,
const uint8_t uQCBORTypes[],
const uint64_t uTagNumbers[],
QCBORTagContentCallBack *pfCB,
@@ -386,8 +389,9 @@
uOffset,
uQCBORTypes,
uTagNumbers,
- uTagRequirement,
- &bTypeMatched);
+ uTagReq,
+ &bTypeMatched);
+
if(uErr != QCBOR_SUCCESS) {
goto Done;
}
@@ -410,7 +414,7 @@
void
QCBORDecode_Private_ProcessTagItem(QCBORDecodeContext *pMe,
QCBORItem *pItem,
- enum QCBORDecodeTagReq uTagRequirement,
+ enum QCBORDecodeTagReq uTagReq,
const uint8_t uQCBORTypes[],
const uint64_t uTagNumber,
QCBORTagContentCallBack *pfCB,
@@ -423,7 +427,7 @@
QCBORDecode_Private_ProcessTagItemMulti(pMe,
pItem,
- uTagRequirement,
+ uTagReq,
uQCBORTypes,
auTagNumbers,
pfCB,
@@ -434,7 +438,7 @@
static void
QCBORDecode_Private_ProcessTagOne(QCBORDecodeContext *pMe,
QCBORItem *pItem,
- enum QCBORDecodeTagReq uTagRequirement,
+ enum QCBORDecodeTagReq uTagReq,
const uint8_t uQCBORType,
const uint64_t uTagNumber,
QCBORTagContentCallBack *pfCB,
@@ -447,7 +451,7 @@
QCBORDecode_Private_ProcessTagItem(pMe,
pItem,
- uTagRequirement,
+ uTagReq,
auQCBORType,
uTagNumber,
pfCB,
@@ -457,7 +461,7 @@
void
QCBORDecode_Private_GetTaggedString(QCBORDecodeContext *pMe,
- enum QCBORDecodeTagReq uTagRequirement,
+ enum QCBORDecodeTagReq uTagReq,
const uint8_t uQCBOR_Type,
const uint64_t uTagNumber,
UsefulBufC *pStr)
@@ -468,7 +472,7 @@
QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
- uTagRequirement,
+ uTagReq,
uQCBOR_Type,
uTagNumber,
QCBORDecode_StringsTagCB,
@@ -500,7 +504,7 @@
void
QCBORDecode_Private_GetTaggedStringInMapN(QCBORDecodeContext *pMe,
const int64_t nLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const uint8_t uQCBOR_Type,
const uint64_t uTagNumber,
UsefulBufC *pString)
@@ -515,7 +519,7 @@
&uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
- uTagRequirement,
+ uTagReq,
uQCBOR_Type,
uTagNumber,
QCBORDecode_StringsTagCB,
@@ -545,7 +549,7 @@
void
QCBORDecode_Private_GetTaggedStringInMapSZ(QCBORDecodeContext *pMe,
const char *szLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
uint8_t uQCBOR_Type,
uint64_t uTagNumber,
UsefulBufC *pString)
@@ -560,7 +564,7 @@
&uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
- uTagRequirement,
+ uTagReq,
uQCBOR_Type,
uTagNumber,
QCBORDecode_StringsTagCB,
@@ -592,7 +596,7 @@
static QCBORError
QCBORDecode_Private_EnterBstrWrapped(QCBORDecodeContext *pMe,
const QCBORItem *pItem,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
const size_t uOffset,
UsefulBufC *pBstr)
{
@@ -624,7 +628,7 @@
uOffset,
uTypes,//TODO: maybe empty?
uTagNumbers,
- uTagRequirement,
+ uTagReq,
&bTypeMatched);
if(pItem->uDataType != QCBOR_TYPE_BYTE_STRING) {
@@ -659,8 +663,7 @@
goto Done;
}
- const size_t uStartOfBstr = UsefulInputBuf_PointerToOffset(&(pMe->InBuf),
- pItem->val.string.ptr);
+ const size_t uStartOfBstr = UsefulInputBuf_PointerToOffset(&(pMe->InBuf), pItem->val.string.ptr);
/* This check makes the cast of uStartOfBstr to uint32_t below safe. */
if(uStartOfBstr == SIZE_MAX || uStartOfBstr > QCBOR_MAX_DECODE_INPUT_SIZE) {
/* This should never happen because pItem->val.string.ptr should
@@ -686,7 +689,7 @@
/* Public function; see qcbor_tag_decode.h */
void
QCBORDecode_EnterBstrWrapped(QCBORDecodeContext *pMe,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
UsefulBufC *pBstr)
{
QCBORItem Item;
@@ -695,7 +698,7 @@
QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
pMe->uLastError = (uint8_t)QCBORDecode_Private_EnterBstrWrapped(pMe,
&Item,
- uTagRequirement,
+ uTagReq,
uOffset,
pBstr);
}
@@ -705,7 +708,7 @@
void
QCBORDecode_EnterBstrWrappedFromMapN(QCBORDecodeContext *pMe,
const int64_t nLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
UsefulBufC *pBstr)
{
QCBORItem Item;
@@ -718,7 +721,7 @@
&uOffset);
pMe->uLastError = (uint8_t)QCBORDecode_Private_EnterBstrWrapped(pMe,
&Item,
- uTagRequirement,
+ uTagReq,
uOffset,
pBstr);
}
@@ -728,7 +731,7 @@
void
QCBORDecode_EnterBstrWrappedFromMapSZ(QCBORDecodeContext *pMe,
const char *szLabel,
- const enum QCBORDecodeTagReq uTagRequirement,
+ const enum QCBORDecodeTagReq uTagReq,
UsefulBufC *pBstr)
{
QCBORItem Item;
@@ -741,7 +744,7 @@
&uOffset);
pMe->uLastError = (uint8_t)QCBORDecode_Private_EnterBstrWrapped(pMe,
&Item,
- uTagRequirement,
+ uTagReq,
uOffset,
pBstr);
}
@@ -768,7 +771,7 @@
the bstr wrapped CBOR was entered.
*/
UsefulInputBuf_SetBufferLength(&(pMe->InBuf),
- DecodeNesting_GetPreviousBoundedEnd(&(pMe->nesting)));
+ DecodeNesting_GetPreviousBoundedEnd(&(pMe->nesting)));
QCBORError uErr = QCBORDecode_Private_ExitBoundedLevel(pMe, uEndOfBstr);
@@ -937,8 +940,7 @@
QCBORError uErr;
const uint8_t puTypes[] = {QCBOR_TYPE_MIME, QCBOR_TYPE_BINARY_MIME, QCBOR_TYPE_NONE};
-
- const uint64_t puTNs[] = {CBOR_TAG_MIME, CBOR_TAG_BINARY_MIME, CBOR_TAG_INVALID64};
+ const uint64_t puTNs[] = {CBOR_TAG_MIME, CBOR_TAG_BINARY_MIME, CBOR_TAG_INVALID64};
QCBORDecode_Private_ProcessTagItemMulti(pMe,
pItem,
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index eb86736..ee19bbc 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -6244,7 +6244,7 @@
true,
QCBOR_SUCCESS, /* for GetNext */
- QCBOR_TYPE_BIGFLOAT_POS_BIGNUM,
+ QCBOR_TYPE_BIGFLOAT_POS_BIGMANTISSA,
-20,
0,
0UL,
@@ -6340,7 +6340,7 @@
true,
QCBOR_SUCCESS, /* for GetNext */
- QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM,
+ QCBOR_TYPE_BIGFLOAT_NEG_BIGMANTISSA,
9223372036854775807,
0,
0UL,
@@ -6372,7 +6372,7 @@
true,
QCBOR_SUCCESS, /* for GetNext */
- QCBOR_TYPE_BIGFLOAT_NEG_U64,
+ QCBOR_TYPE_BIGFLOAT_NEG_U64MANTISSA,
9223372036854775807,
0,
0xffffffffffffffff,
@@ -6404,7 +6404,7 @@
true,
QCBOR_SUCCESS, /* for GetNext */
- QCBOR_TYPE_BIGFLOAT_POS_U64,
+ QCBOR_TYPE_BIGFLOAT_POS_U64MANTISSA,
9223372036854775807,
0,
0xffffffffffffffff,
@@ -6509,8 +6509,8 @@
if(pT->nMantissaGN != Item.val.expAndMantissa.Mantissa.nInt) {
return (int32_t)(1+uIndex) * 1000 + 4;
}
- } else if(Item.uDataType == QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64 || Item.uDataType == QCBOR_TYPE_BIGFLOAT_NEG_U64 ||
- Item.uDataType == QCBOR_TYPE_DECIMAL_FRACTION_POS_U64 || Item.uDataType == QCBOR_TYPE_BIGFLOAT_POS_U64) {
+ } else if(Item.uDataType == QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64 || Item.uDataType == QCBOR_TYPE_BIGFLOAT_NEG_U64MANTISSA ||
+ Item.uDataType == QCBOR_TYPE_DECIMAL_FRACTION_POS_U64 || Item.uDataType == QCBOR_TYPE_BIGFLOAT_POS_U64MANTISSA) {
if(pT->uMantissaGU != Item.val.expAndMantissa.Mantissa.uInt) {
return (int32_t)(1+uIndex) * 1000 + 4;
}