merge and #ifdef fan out fixes
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 4ec0628..1e233d2 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -17,6 +17,10 @@
- os-image: ubuntu-latest
container: ubuntu:22.04
+ dis-xxx: '-DQCBOR_DISABLE_NON_INTEGER_LABELS'
+
+ - os-image: ubuntu-latest
+ container: ubuntu:22.04
dis-xxx: '-DQCBOR_DISABLE_TAGS'
- os-image: ubuntu-latest
diff --git a/README.md b/README.md
index a4f400a..5160cb9 100644
--- a/README.md
+++ b/README.md
@@ -443,7 +443,7 @@
| QCBOR_DISABLE_PREFERRED_FLOAT | 900 |
| QCBOR_DISABLE_FLOAT_HW_USE | 50 |
| QCBOR_DISABLE_TAGS | 400 |
- | QCBOR_DISABLE_NON_INTEGER_LABELS | 200 |
+ | QCBOR_DISABLE_NON_INTEGER_LABELS | 140 |
| USEFULBUF_DISABLE_ALL_FLOAT | 950 |
QCBOR_DISABLE_ENCODE_USAGE_GUARDS affects encoding only. It doesn't
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 61626d4..0a7eca0 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -517,12 +517,13 @@
union {
/** The label for @c uLabelType for @ref QCBOR_TYPE_INT64 */
int64_t int64;
- // TODO: ifdef these out?
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
/** The label for @c uLabelType for @ref QCBOR_TYPE_UINT64 */
uint64_t uint64;
/** The label for @c uLabelType @ref QCBOR_TYPE_BYTE_STRING and
* @ref QCBOR_TYPE_TEXT_STRING */
UsefulBufC string;
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
} label;
#ifndef QCBOR_DISABLE_TAGS
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index ebb4b65..eb46210 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -2236,6 +2236,7 @@
QCBORItem *pItem,
UsefulBufC *pEncodedCBOR)
{
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
QCBORItem OneItemSeach[2];
OneItemSeach[0].uLabelType = QCBOR_TYPE_TEXT_STRING;
OneItemSeach[0].label.string = UsefulBuf_FromSZ(szLabel);
@@ -2243,6 +2244,12 @@
OneItemSeach[1].uLabelType = QCBOR_TYPE_NONE;
QCBORDecode_Private_SearchAndGetArrayOrMap(pMe, OneItemSeach, pItem, pEncodedCBOR);
+#else
+ (void)szLabel;
+ (void)pItem;
+ (void)pEncodedCBOR;
+ pMe->uLastError = QCBOR_ERR_MAP_LABEL_TYPE;
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
}
static inline void
@@ -2276,6 +2283,7 @@
QCBORItem *pItem,
UsefulBufC *pEncodedCBOR)
{
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
QCBORItem OneItemSeach[2];
OneItemSeach[0].uLabelType = QCBOR_TYPE_TEXT_STRING;
OneItemSeach[0].label.string = UsefulBuf_FromSZ(szLabel);
@@ -2283,6 +2291,12 @@
OneItemSeach[1].uLabelType = QCBOR_TYPE_NONE;
QCBORDecode_Private_SearchAndGetArrayOrMap(pMe, OneItemSeach, pItem, pEncodedCBOR);
+#else
+ (void)szLabel;
+ (void)pItem;
+ (void)pEncodedCBOR;
+ pMe->uLastError = QCBOR_ERR_MAP_LABEL_TYPE;
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
}
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 49af24a..30253c2 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -107,7 +107,7 @@
return uDataType == QCBOR_TYPE_MAP ||
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
uDataType == QCBOR_TYPE_MAP_AS_ARRAY ||
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
uDataType == QCBOR_TYPE_ARRAY;
}
@@ -152,6 +152,7 @@
if(Item2.uLabelType == QCBOR_TYPE_INT64 && Item1.label.int64 == Item2.label.int64) {
return true;
}
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
} else if(Item1.uLabelType == QCBOR_TYPE_TEXT_STRING) {
if(Item2.uLabelType == QCBOR_TYPE_TEXT_STRING && !UsefulBuf_Compare(Item1.label.string, Item2.label.string)) {
return true;
@@ -164,6 +165,7 @@
if(Item2.uLabelType == QCBOR_TYPE_UINT64 && Item1.label.uint64 == Item2.label.uint64) {
return true;
}
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
}
/* Other label types are never matched */
@@ -379,7 +381,7 @@
if(uItemDataType == QCBOR_TYPE_MAP_AS_ARRAY) {
uItemDataType = QCBOR_TYPE_ARRAY;
}
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
if(uItemDataType != uType) {
return false;
@@ -1089,43 +1091,50 @@
/**
* @brief Decode text and byte strings
*
- * @param[in] pAllocator The string allocator or NULL.
+ * @param[in] pMe Decoder context.
+ * @param[in] bAllocate Whether to allocate and copy string.
+ * @param[in] nMajorType Whether it is a byte or text string.
* @param[in] uStrLen The length of the string.
- * @param[in] pUInBuf The surce from which to read the string's bytes.
- * @param[out] pDecodedItem The filled in decoded item.
+ * @param[in] nAdditionalInfo Whether it is an indefinite-length string.
+ * @param[out] pDecodedItem The filled-in decoded item.
*
* @retval QCBOR_ERR_HIT_END Unexpected end of input.
* @retval QCBOR_ERR_STRING_ALLOCATE Out of memory.
* @retval QCBOR_ERR_STRING_TOO_LONG String longer than SIZE_MAX - 4.
+ * @retval QCBOR_ERR_NO_STRING_ALLOCATOR Allocation requested, but no allocator
*
- * The reads @c uStrlen bytes from @c pUInBuf and fills in @c
- * pDecodedItem. If @c pAllocator is not NULL then memory for the
- * string is allocated.
+ * This reads @c uStrlen bytes from the input and fills in @c
+ * pDecodedItem. If @c bAllocate is true, then memory for the string
+ * is allocated.
*/
static QCBORError
-QCBOR_Private_DecodeBytes(const QCBORInternalAllocator *pAllocator,
- int nMajorType,
- const uint64_t uStrLen,
- int nAdditionalInfo,
- UsefulInputBuf *pUInBuf,
- QCBORItem *pDecodedItem)
+QCBOR_Private_DecodeString(QCBORDecodeContext *pMe,
+ const bool bAllocate,
+ const int nMajorType,
+ const uint64_t uStrLen,
+ const int nAdditionalInfo,
+ QCBORItem *pDecodedItem)
{
QCBORError uReturn = QCBOR_SUCCESS;
+ /* ---- Figure out the major type ---- */
#if CBOR_MAJOR_TYPE_BYTE_STRING + 4 != QCBOR_TYPE_BYTE_STRING
- #error QCBOR_TYPE_BYTE_STRING no lined up with major type
+ #error QCBOR_TYPE_BYTE_STRING not lined up with major type
#endif
#if CBOR_MAJOR_TYPE_TEXT_STRING + 4 != QCBOR_TYPE_TEXT_STRING
- #error QCBOR_TYPE_TEXT_STRING no lined up with major type
+ #error QCBOR_TYPE_TEXT_STRING not lined up with major type
#endif
pDecodedItem->uDataType = (uint8_t)(nMajorType + 4);
-
if(nAdditionalInfo == LEN_IS_INDEFINITE) {
+ /* --- Just the head of an indefinite-length string --- */
pDecodedItem->val.string = (UsefulBufC){NULL, QCBOR_STRING_LENGTH_INDEFINITE};
} else {
+ /* --- A definite-length string --- */
+ /* --- (which might be a chunk of an indefinte-length string) --- */
+
/* CBOR lengths can be 64 bits, but size_t is not 64 bits on all
* CPUs. This check makes the casts to size_t below safe.
*
@@ -1138,7 +1147,7 @@
goto Done;
}
- const UsefulBufC Bytes = UsefulInputBuf_GetUsefulBuf(pUInBuf, (size_t)uStrLen);
+ const UsefulBufC Bytes = UsefulInputBuf_GetUsefulBuf(&(pMe->InBuf), (size_t)uStrLen);
if(UsefulBuf_IsNULLC(Bytes)) {
/* Failed to get the bytes for this string item */
uReturn = QCBOR_ERR_HIT_END;
@@ -1146,14 +1155,21 @@
}
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
- /* Note that this is not where allocation to coalesce
- * indefinite-length strings is done. This is for when the caller
- * has requested all strings be allocated. Disabling indefinite
- * length strings also disables this allocate-all option.
- */
- if(pAllocator) {
- /* request to use the string allocator to make a copy */
- UsefulBuf NewMem = StringAllocator_Allocate(pAllocator, (size_t)uStrLen);
+ if(bAllocate) {
+ /* --- Put string in allocated memory --- */
+
+ /* Note that this is not where allocation to coalesce
+ * indefinite-length strings is done. This is for when the
+ * caller has requested all strings be allocated. Disabling
+ * indefinite length strings also disables this allocate-all
+ * option.
+ */
+
+ if(pMe->StringAllocator.pfAllocator == NULL) {
+ uReturn = QCBOR_ERR_NO_STRING_ALLOCATOR;
+ goto Done;
+ }
+ UsefulBuf NewMem = StringAllocator_Allocate(&(pMe->StringAllocator), (size_t)uStrLen);
if(UsefulBuf_IsNULL(NewMem)) {
uReturn = QCBOR_ERR_STRING_ALLOCATE;
goto Done;
@@ -1162,11 +1178,11 @@
pDecodedItem->uDataAlloc = 1;
goto Done;
}
-#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
- (void)pAllocator;
+#else
+ (void)bAllocate;
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
- /* Normal case with no string allocator */
+ /* --- Normal case with no string allocator --- */
pDecodedItem->val.string = Bytes;
}
@@ -1177,7 +1193,25 @@
-
+/**
+ * @brief Decode array or map.
+ *
+ * @param[in] uMode Decoder mode.
+ * @param[in] nMajorType Whether it is a byte or text string.
+ * @param[in] uItemCount The length of the string.
+ * @param[in] nAdditionalInfo Whether it is an indefinite-length.
+ * @param[out] pDecodedItem The filled-in decoded item.
+ *
+ * @retval QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED Indefinites disabled.
+ * @retval QCBOR_ERR_ARRAY_DECODE_TOO_LONG Too many items in array/map.
+ *
+ * Not much to do for arrays and maps. Just the type
+ * item count.
+ *
+ * This also does the bulk of the work for QCBOR_DECODE_MODE_MAP_AS_ARRAY,
+ * a special mode to handle arbitrarily complex map labels. This
+ * ifdefs out with QCBOR_DISABLE_NON_INTEGER_LABELS.
+ */
static QCBORError
QCBOR_Private_DecodeArrayOrMap(const uint8_t uMode,
const int nMajorType,
@@ -1202,12 +1236,12 @@
}
#else
(void)uMode;
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
uReturn = QCBOR_SUCCESS;
if(nAdditionalInfo == LEN_IS_INDEFINITE) {
- /* ------ Indefinite-length arra/map ----- */
+ /* ------ Indefinite-length array/map ----- */
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
pDecodedItem->val.uCount = QCBOR_COUNT_INDICATES_INDEFINITE_LENGTH;
#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
@@ -1227,7 +1261,7 @@
}
} else
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
{
/* ------ Definite-length array/map ------ */
if(uItemCount > QCBOR_MAX_ITEMS_IN_ARRAY) {
@@ -1248,7 +1282,7 @@
*
* param[in] pUInBuf Input buffer to read data item from.
* @param[out] pDecodedItem The filled-in decoded item.
- * @param[in] pAllocator The allocator to use for strings or NULL.
+ * param[in] pAllocator The allocator to use for strings or NULL.
*
* @retval QCBOR_ERR_UNSUPPORTED Encountered unsupported/reserved
* features
@@ -1271,8 +1305,8 @@
*/
static QCBORError
QCBOR_Private_DecodeAtomicDataItem(QCBORDecodeContext *pMe,
- QCBORItem *pDecodedItem,
- const QCBORInternalAllocator *pAllocator)
+ const bool bAllocateStrings,
+ QCBORItem *pDecodedItem)
{
QCBORError uReturn;
@@ -1300,7 +1334,7 @@
case CBOR_MAJOR_TYPE_BYTE_STRING: /* Major type 2 */
case CBOR_MAJOR_TYPE_TEXT_STRING: /* Major type 3 */
- uReturn = QCBOR_Private_DecodeBytes(pAllocator, nMajorType, uArgument, nAdditionalInfo, &(pMe->InBuf), pDecodedItem);
+ uReturn = QCBOR_Private_DecodeString(pMe, bAllocateStrings, nMajorType, uArgument, nAdditionalInfo, pDecodedItem);
break;
case CBOR_MAJOR_TYPE_ARRAY: /* Major type 4 */
@@ -1376,57 +1410,26 @@
* QCBORItem 56 52
* TOTAL 120 74
*/
-
- /* The string allocator is used here for two purposes: 1)
- * coalescing the chunks of an indefinite-length string, 2)
- * allocating storage for every string returned when requested.
- *
- * The first use is below in this function. Indefinite-length
- * strings cannot be processed at all without a string allocator.
- *
- * The second used is in DecodeBytes() which is called by
- * GetNext_Item() below. This second use unneccessary for most use
- * and only happens when requested in the call to
- * QCBORDecode_SetMemPool(). If the second use not requested then
- * NULL is passed for the string allocator to GetNext_Item().
- *
- * QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS disables the string
- * allocator altogether and thus both of these uses. It reduced the
- * decoder object code by about 400 bytes.
- */
- const QCBORInternalAllocator *pAllocatorForGetNext = NULL;
-
-#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
- const QCBORInternalAllocator *pAllocator = NULL;
-
- if(pMe->StringAllocator.pfAllocator) {
- pAllocator = &(pMe->StringAllocator);
- if(pMe->bStringAllocateAll) {
- pAllocatorForGetNext = pAllocator;
- }
- }
-#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
-
QCBORError uReturn;
- uReturn = QCBOR_Private_DecodeAtomicDataItem(pMe, pDecodedItem, pAllocatorForGetNext);
+
+ uReturn = QCBOR_Private_DecodeAtomicDataItem(pMe, pMe->bStringAllocateAll, pDecodedItem);
if(uReturn != QCBOR_SUCCESS) {
goto Done;
}
- /* Only do indefinite-length processing on strings */
+ /* Skip out if not an indefinite-length string */
const uint8_t uStringType = pDecodedItem->uDataType;
- if(uStringType!= QCBOR_TYPE_BYTE_STRING && uStringType != QCBOR_TYPE_TEXT_STRING) {
+ if(uStringType != QCBOR_TYPE_BYTE_STRING &&
+ uStringType != QCBOR_TYPE_TEXT_STRING) {
goto Done;
}
-
- /* Is this a string with an indefinite length? */
if(pDecodedItem->val.string.len != QCBOR_STRING_LENGTH_INDEFINITE) {
goto Done;
}
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
/* Can't decode indefinite-length strings without a string allocator */
- if(pAllocator == NULL) {
+ if(!pMe->StringAllocator.pfAllocator) {
uReturn = QCBOR_ERR_NO_STRING_ALLOCATOR;
goto Done;
}
@@ -1437,12 +1440,12 @@
for(;;) {
/* Get QCBORItem for next chunk */
QCBORItem StringChunkItem;
- /* Pass a NULL string allocator to GetNext_Item() because the
- * individual string chunks in an indefinite-length should not
- * be allocated. They are always copied in the the contiguous
+ /* Pass a false to DecodeAtomicDataItem() because the
+ * individual string chunks in an indefinite-length must not
+ * be allocated. They are always copied into the allocated contiguous
* buffer allocated here.
*/
- uReturn = QCBOR_Private_DecodeAtomicDataItem(pMe, &StringChunkItem, NULL);
+ uReturn = QCBOR_Private_DecodeAtomicDataItem(pMe, false, &StringChunkItem);
if(uReturn) {
break;
}
@@ -1471,10 +1474,9 @@
* equivalent to StringAllocator_Allocate(). Subsequently it is
* not NULL and a reallocation happens.
*/
- UsefulBuf NewMem = StringAllocator_Reallocate(pAllocator,
+ UsefulBuf NewMem = StringAllocator_Reallocate(&(pMe->StringAllocator),
FullString.ptr,
FullString.len + StringChunkItem.val.string.len);
-
if(UsefulBuf_IsNULL(NewMem)) {
uReturn = QCBOR_ERR_STRING_ALLOCATE;
break;
@@ -1487,7 +1489,7 @@
if(uReturn != QCBOR_SUCCESS && !UsefulBuf_IsNULLC(FullString)) {
/* Getting the item failed, clean up the allocated memory */
- StringAllocator_Free(pAllocator, FullString.ptr);
+ StringAllocator_Free(&(pMe->StringAllocator), FullString.ptr);
}
#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
uReturn = QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED;
@@ -1820,7 +1822,7 @@
if(UsefulInputBuf_BytesUnconsumed(&(pMe->InBuf)) != 0) {
QCBORItem Peek;
size_t uPeek = UsefulInputBuf_Tell(&(pMe->InBuf));
- QCBORError uReturn = QCBOR_Private_DecodeAtomicDataItem(pMe, &Peek, NULL);
+ QCBORError uReturn = QCBOR_Private_DecodeAtomicDataItem(pMe, false, &Peek);
if(uReturn != QCBOR_SUCCESS) {
return uReturn;
}
@@ -3542,6 +3544,7 @@
return;
}
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
QCBORItem OneItemSeach[2];
OneItemSeach[0].uLabelType = QCBOR_TYPE_TEXT_STRING;
OneItemSeach[0].label.string = UsefulBuf_FromSZ(szLabel);
@@ -3559,8 +3562,16 @@
}
*pItem = OneItemSeach[0];
-
Done:
+
+#else
+ (void)pMe;
+ (void)szLabel;
+ (void)uQcborType;
+ (void)pItem;
+ QCBORError uReturn = QCBOR_ERR_LABEL_NOT_FOUND;
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
+
pMe->uLastError = (uint8_t)uReturn;
}
@@ -3615,7 +3626,7 @@
if(uItemDataType == QCBOR_TYPE_MAP_AS_ARRAY) {
uItemDataType = QCBOR_TYPE_ARRAY;
}
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
if(uItemDataType != uType) {
pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
@@ -4032,6 +4043,7 @@
void
QCBORDecode_EnterMapFromMapSZ(QCBORDecodeContext *pMe, const char *szLabel)
{
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
QCBORItem OneItemSeach[2];
OneItemSeach[0].uLabelType = QCBOR_TYPE_TEXT_STRING;
OneItemSeach[0].label.string = UsefulBuf_FromSZ(szLabel);
@@ -4039,6 +4051,10 @@
OneItemSeach[1].uLabelType = QCBOR_TYPE_NONE;
QCBORDecode_Private_SearchAndEnter(pMe, OneItemSeach);
+#else
+ (void)szLabel;
+ pMe->uLastError = QCBOR_ERR_LABEL_NOT_FOUND;
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
}
/*
@@ -4062,6 +4078,7 @@
void
QCBORDecode_EnterArrayFromMapSZ(QCBORDecodeContext *pMe, const char *szLabel)
{
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
QCBORItem OneItemSeach[2];
OneItemSeach[0].uLabelType = QCBOR_TYPE_TEXT_STRING;
OneItemSeach[0].label.string = UsefulBuf_FromSZ(szLabel);
@@ -4069,6 +4086,10 @@
OneItemSeach[1].uLabelType = QCBOR_TYPE_NONE;
QCBORDecode_Private_SearchAndEnter(pMe, OneItemSeach);
+#else
+ (void)szLabel;
+ pMe->uLastError = QCBOR_ERR_LABEL_NOT_FOUND;
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
}
@@ -4104,11 +4125,13 @@
}
uint8_t uItemDataType = Item.uDataType;
+
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
if(uItemDataType == QCBOR_TYPE_MAP_AS_ARRAY ) {
uItemDataType = QCBOR_TYPE_ARRAY;
}
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
+
if(uItemDataType != uType) {
uErr = QCBOR_ERR_UNEXPECTED_TYPE;
goto Done;
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 2bceef2..5be3876 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1139,6 +1139,7 @@
#endif
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
/*
Decode and thoroughly check a moderately complex
set of maps. Can be run in QCBOR_DECODE_MODE_NORMAL or in
@@ -1266,7 +1267,7 @@
return 0;
}
-
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
/* This test requires indef strings, HW float and preferred float,... */
#if !defined(QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS) && \
@@ -2089,6 +2090,7 @@
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
/*
Fully or partially decode pValidMapEncoded. When
@@ -2296,7 +2298,6 @@
-
int32_t ParseMapTest(void)
{
// Parse a moderatly complex map structure very thoroughly
@@ -2324,6 +2325,7 @@
return nResult;
}
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
/* The simple-values including some not well formed */
@@ -4585,7 +4587,6 @@
}
-
static int32_t CheckItemWithIntLabel(QCBORDecodeContext *pCtx,
uint8_t uDataType,
uint8_t uNestingLevel,
@@ -4599,15 +4600,13 @@
if((nCBORError = QCBORDecode_GetNext(pCtx, &Item))) return -1;
if(Item.uDataType != uDataType) return -1;
if(uNestingLevel > 0) {
- if(Item.uLabelType != QCBOR_TYPE_INT64 &&
- Item.uLabelType != QCBOR_TYPE_UINT64) {
+ if(Item.uLabelType != QCBOR_TYPE_INT64) {
return -1;
}
- if(Item.uLabelType == QCBOR_TYPE_INT64) {
- if(Item.label.int64 != nLabel) return -1;
- } else {
- if(Item.label.uint64 != (uint64_t)nLabel) return -1;
+ if(Item.label.int64 != nLabel) {
+ return -1;
}
+
}
if(Item.uNestingLevel != uNestingLevel) return -1;
if(Item.uNextNestLevel != uNextNest) return -1;
@@ -4618,7 +4617,6 @@
return 0;
}
-
// Same code checks definite and indefinite length versions of the map
static int32_t CheckCSRMaps(QCBORDecodeContext *pDC)
{
@@ -5030,7 +5028,7 @@
0xff, // ending break
0x01 // integer being labeled.
};
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
/**
Make an indefinite length string
@@ -5374,7 +5372,7 @@
if(nCBORError != QCBOR_ERR_STRING_ALLOCATE) {
return -10;
}
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
return 0;
}
@@ -6799,14 +6797,13 @@
}
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
-
(void)pValidMapIndefEncoded;
nReturn = SpiffyDecodeBasicMap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapIndefEncoded));
if(nReturn) {
return nReturn + 20000;
}
-#endif
-#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
+#endif /* ! QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
QCBORItem ArrayItem;
@@ -6896,16 +6893,20 @@
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spSimpleArray), 0);
QCBORDecode_EnterArray(&DCtx, NULL);
int64_t nDecodedInt2;
+
+ UsefulBufC String;
+ QCBORDecode_GetTextStringInMapN(&DCtx, 88, &String);
+ uErr = QCBORDecode_GetAndResetError(&DCtx);
+ if(uErr != QCBOR_ERR_MAP_NOT_ENTERED){
+ return 2009;
+ }
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
QCBORDecode_GetInt64InMapSZ(&DCtx, "another int", &nDecodedInt2);
uErr = QCBORDecode_GetAndResetError(&DCtx);
if(uErr != QCBOR_ERR_MAP_NOT_ENTERED){
return 2008;
}
- UsefulBufC String;
- QCBORDecode_GetTextStringInMapN(&DCtx, 88, &String);
- if(uErr != QCBOR_ERR_MAP_NOT_ENTERED){
- return 2009;
- }
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEmptyMap), 0);
@@ -7081,7 +7082,7 @@
if(QCBORDecode_GetError(&DCtx)) {
return 2410;
}
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
nReturn = DecodeNestedIterate();
@@ -8631,6 +8632,7 @@
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
/*
* An array of an integer and an array. The second array contains
* a bstr-wrapped map.
@@ -8691,11 +8693,11 @@
0x73,
0xff, 0xff
};
-#endif
-
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
static const uint8_t pWithEmptyMap[] = {0x82, 0x18, 0x64, 0xa0};
+
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
static const uint8_t pWithEmptyMapInDef[] = {0x9f, 0x18, 0x64, 0xbf, 0xff, 0xff};
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
@@ -8721,7 +8723,9 @@
};
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+#endif
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
int32_t PeekAndRewindTest(void)
{
QCBORItem Item;
@@ -9338,7 +9342,7 @@
}
*/
-#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+#endif /* ! QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
// Rewind an indefnite length byte-string wrapped sequence
@@ -9346,7 +9350,7 @@
return 0;
}
-
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
static const uint8_t spBooleansInMap[] =
@@ -9518,7 +9522,7 @@
}
-
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
static const uint8_t spExpectedArray2s[] = {
0x82, 0x67, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67,
0x31, 0x67, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67,
@@ -9568,13 +9572,13 @@
};
#endif /* !QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
-
#ifndef QCBOR_DISABLE_TAGS
/* An exp / mant tag in two nested arrays */
static const uint8_t spExpMant[] = {0x81, 0x81, 0xC4, 0x82, 0x20, 0x03};
#endif /* !QCBOR_DISABLE_TAGS */
+#endif
-
+#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
int32_t GetMapAndArrayTest(void)
{
QCBORDecodeContext DCtx;
@@ -9839,10 +9843,11 @@
if(uPosition != QCBORDecode_Tell(&DCtx)) {
return 102;
}
-#endif /* !QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+#endif /* ! QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
return 0;
}
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
int32_t
diff --git a/test/run_tests.c b/test/run_tests.c
index a28f3d7..a600731 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -71,7 +71,7 @@
TEST_ENTRY(TellTests),
TEST_ENTRY(ParseMapAsArrayTest),
TEST_ENTRY(SpiffyDateDecodeTest),
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
TEST_ENTRY(ErrorHandlingTests),
TEST_ENTRY(OpenCloseBytesTest),
TEST_ENTRY(EnterBstrTest),
@@ -103,7 +103,7 @@
TEST_ENTRY(ComprehensiveInputTest),
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
TEST_ENTRY(ParseMapTest),
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
TEST_ENTRY(BasicEncodeTest),
TEST_ENTRY(NestedMapTest),
TEST_ENTRY(BignumParseTest),
@@ -123,7 +123,7 @@
TEST_ENTRY(IndefiniteLengthStringTest),
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
TEST_ENTRY(SpiffyIndefiniteLengthStringsTests),
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
TEST_ENTRY(SetUpAllocatorTest),
TEST_ENTRY(CBORTestIssue134),
#endif /* #ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
@@ -141,7 +141,7 @@
TEST_ENTRY(CoseSign1TBSTest),
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
TEST_ENTRY(StringDecoderModeFailTest),
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
TEST_ENTRY_DISABLED(BigComprehensiveInputTest),
TEST_ENTRY_DISABLED(TooLargeInputTest),
TEST_ENTRY(EncodeErrorTests),
@@ -153,7 +153,7 @@
TEST_ENTRY(IntToTests),
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
TEST_ENTRY(PeekAndRewindTest),
-#endif
+#endif /* ! QCBOR_DISABLE_NON_INTEGER_LABELS */
#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
TEST_ENTRY(ExponentAndMantissaDecodeTests),
#ifndef QCBOR_DISABLE_TAGS