Added test for decode maps as strings mode
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 8eaeb43..1b4ee1a 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -950,41 +950,45 @@
}
// If in a map and the right decoding mode, get the label
- if(DecodeNesting_TypeIsMap(&(me->nesting)) && me->uDecodeMode != QCBOR_DECODE_MODE_MAP_AS_ARRAY) {
- // In a map and caller wants maps decoded, not treated as arrays
-
- // Get the next item which will be the real data; Item will be the label
- QCBORItem LabelItem = *pDecodedItem;
- nReturn = GetNext_TaggedItem(me, pDecodedItem, pTags);
- if(nReturn)
- goto Done;
-
- pDecodedItem->uLabelAlloc = LabelItem.uDataAlloc;
-
- if(LabelItem.uDataType == QCBOR_TYPE_TEXT_STRING) {
- // strings are always good labels
- pDecodedItem->label.string = LabelItem.val.string;
- pDecodedItem->uLabelType = QCBOR_TYPE_TEXT_STRING;
- } else if (QCBOR_DECODE_MODE_MAP_STRINGS_ONLY == me->uDecodeMode) {
- // It's not a string and we only want strings, probably for easy translation to JSON
- nReturn = QCBOR_ERR_MAP_LABEL_TYPE;
- goto Done;
- } else if(LabelItem.uDataType == QCBOR_TYPE_INT64) {
- pDecodedItem->label.int64 = LabelItem.val.int64;
- pDecodedItem->uLabelType = QCBOR_TYPE_INT64;
- } else if(LabelItem.uDataType == QCBOR_TYPE_UINT64) {
- pDecodedItem->label.uint64 = LabelItem.val.uint64;
- pDecodedItem->uLabelType = QCBOR_TYPE_UINT64;
- } else if(LabelItem.uDataType == QCBOR_TYPE_BYTE_STRING) {
- pDecodedItem->label.string = LabelItem.val.string;
+ if(DecodeNesting_TypeIsMap(&(me->nesting))) {
+ if(me->uDecodeMode != QCBOR_DECODE_MODE_MAP_AS_ARRAY) {
+ // In a map and caller wants maps decoded, not treated as arrays
+
+ // Get the next item which will be the real data; Item will be the label
+ QCBORItem LabelItem = *pDecodedItem;
+ nReturn = GetNext_TaggedItem(me, pDecodedItem, pTags);
+ if(nReturn)
+ goto Done;
+
pDecodedItem->uLabelAlloc = LabelItem.uDataAlloc;
- pDecodedItem->uLabelType = QCBOR_TYPE_BYTE_STRING;
+
+ if(LabelItem.uDataType == QCBOR_TYPE_TEXT_STRING) {
+ // strings are always good labels
+ pDecodedItem->label.string = LabelItem.val.string;
+ pDecodedItem->uLabelType = QCBOR_TYPE_TEXT_STRING;
+ } else if (QCBOR_DECODE_MODE_MAP_STRINGS_ONLY == me->uDecodeMode) {
+ // It's not a string and we only want strings, probably for easy translation to JSON
+ nReturn = QCBOR_ERR_MAP_LABEL_TYPE;
+ goto Done;
+ } else if(LabelItem.uDataType == QCBOR_TYPE_INT64) {
+ pDecodedItem->label.int64 = LabelItem.val.int64;
+ pDecodedItem->uLabelType = QCBOR_TYPE_INT64;
+ } else if(LabelItem.uDataType == QCBOR_TYPE_UINT64) {
+ pDecodedItem->label.uint64 = LabelItem.val.uint64;
+ pDecodedItem->uLabelType = QCBOR_TYPE_UINT64;
+ } else if(LabelItem.uDataType == QCBOR_TYPE_BYTE_STRING) {
+ pDecodedItem->label.string = LabelItem.val.string;
+ pDecodedItem->uLabelAlloc = LabelItem.uDataAlloc;
+ pDecodedItem->uLabelType = QCBOR_TYPE_BYTE_STRING;
+ } else {
+ // label is not an int or a string. It is an arrray
+ // or a float or such and this implementation doesn't handle that.
+ // Also, tags on labels are ignored.
+ nReturn = QCBOR_ERR_MAP_LABEL_TYPE;
+ goto Done;
+ }
} else {
- // label is not an int or a string. It is an arrray
- // or a float or such and this implementation doesn't handle that.
- // Also, tags on labels are ignored.
- nReturn = QCBOR_ERR_MAP_LABEL_TYPE;
- goto Done;
+ pDecodedItem->val.uCount *= 2; // interpreting maps as arrays
}
}