Officially support udataType == QCBOR_TYPE_NONE on decoding errors
diff --git a/inc/qcbor.h b/inc/qcbor.h
index 18ed472..d541a10 100644
--- a/inc/qcbor.h
+++ b/inc/qcbor.h
@@ -2226,6 +2226,11 @@
to handle newly defined tags, while using very little memory, in
particular keeping @ref QCBORItem as small as possible.
+ If any error occurs, \c uDataType and \c uLabelType will be set
+ to \ref QCBOR_TYPE_NONE. If there is no need to know the specific
+ error, \ref QCBOR_TYPE_NONE can be checked for and the return value
+ ignored.
+
Errors fall in several categories as noted in list above:
- Not well-formed errors are those where there is something
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 4d8027c..b25e3bb 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -1147,6 +1147,10 @@
pDecodedItem->uNextNestLevel = DecodeNesting_GetLevel(&(me->nesting));
Done:
+ if(nReturn != QCBOR_SUCCESS) {
+ // Make sure uDataType and uLabelType are QCBOR_TYPE_NONE
+ memset(pDecodedItem, 0, sizeof(QCBORItem));
+ }
return nReturn;
}
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 2cadf7f..5c8a4a5 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1828,7 +1828,7 @@
sizeof(Failures)/sizeof(struct FailInput);
for(const struct FailInput *pF = &Failures[0]; pF < pFEnd ;pF++) {
- // Set up the decoding context including a mem pool so that
+ // Set up the decoding context including a memory pool so that
// indefinite length items can be checked
QCBORDecodeContext DCtx;
QCBORDecode_Init(&DCtx, pF->Input, QCBOR_DECODE_MODE_NORMAL);
@@ -1838,15 +1838,20 @@
return -9;
}
- // Iterate until there is an error of some sort
+ // Iterate until there is an error of some sort error
+ QCBORItem Item;
do {
- QCBORItem Item;
+ // Set to something none-zero other than QCBOR_TYPE_NONE
+ memset(&Item, 0x33, sizeof(Item));
nCBORError = QCBORDecode_GetNext(&DCtx, &Item);
} while(nCBORError == QCBOR_SUCCESS);
// Must get the expected error or the this test fails
- if(nCBORError != pF->nError) {
+ // The data and label type must also be QCBOR_TYPE_NONE
+ if(nCBORError != pF->nError ||
+ Item.uDataType != QCBOR_TYPE_NONE ||
+ Item.uLabelType != QCBOR_TYPE_NONE) {
// return index of CBOR + 1000
return 1000 + (int)(pF - &Failures[0]);
}