Merge branch 'master' of github.com:laurencelundblade/QCBOR
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 8217073..8e8bdc2 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -2981,6 +2981,8 @@
QCBORDecodeNesting SaveNesting;
DecodeNesting_PrepareForMapSearch(&(pMe->nesting), &SaveNesting);
+ const size_t uSaveCursor = UsefulInputBuf_Tell(&(pMe->InBuf));
+
/* Reposition to search from the start of the map / array */
RewindMapOrArray(pMe);
@@ -3097,6 +3099,7 @@
Done:
DecodeNesting_RestoreFromMapSearch(&(pMe->nesting), &SaveNesting);
+ UsefulInputBuf_Seek(&(pMe->InBuf), uSaveCursor);
Done2:
/* For all items not found, set the data and label type to QCBOR_TYPE_NONE */
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 755d032..92879d6 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -4855,6 +4855,8 @@
}
*/
+
+
int32_t SpiffyDecodeBasicMap(UsefulBufC input)
{
QCBORItem Item1, Item2, Item3;
@@ -4945,6 +4947,7 @@
return 1009;
}
+
return 0;
}
@@ -5230,10 +5233,12 @@
};
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
-const unsigned char not_well_formed_submod_section[] = {
+static const unsigned char not_well_formed_submod_section[] = {
0xa1, 0x14, 0x1f,
};
+static const uint8_t spCOSEHeader[] = { 0xa1, 0x01, 0x26};
+
int32_t EnterMapTest()
{
QCBORItem Item1;
@@ -5575,6 +5580,27 @@
return 2500;
}
+ /* Make sure failure to get an item doesn't disturb cursor. */
+ QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCOSEHeader), 0);
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_EnterArrayFromMapN(&DCtx, 55);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_LABEL_NOT_FOUND) {
+ return 2601;
+ }
+
+ QCBORDecode_GetNext(&DCtx, &Item1);
+ if(Item1.uDataType != QCBOR_TYPE_INT64 ||
+ Item1.val.int64 != -7 ||
+ QCBORDecode_GetError(&DCtx) != QCBOR_SUCCESS) {
+ return 2600;
+ }
+
+ QCBORDecode_ExitMap(&DCtx);
+ uErr = QCBORDecode_Finish(&DCtx);
+ if(uErr != QCBOR_SUCCESS) {
+ return 2026;
+ }
+
return nReturn;
}