Make rewind work when not bounded and reset error state
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index df0067b..5288240 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -720,6 +720,21 @@
 
 
 /**
+ @brief Reset traversal cursor to start of map, array or start of input CBOR.
+
+ @param[in] pCtx   The decode context.
+
+ If an array or map has been entered this sets the traversal cursor to
+ its beginning. If no map or array has been entered, this resets the
+ traversal cursor to the beginning of the input CBOR.
+
+ This also resets the error state.
+
+ */
+void QCBORDecode_Rewind(QCBORDecodeContext *pCtx);
+
+
+/**
  @brief Exit a map that has been enetered.
 
  @param[in] pCtx   The decode context.
@@ -729,7 +744,7 @@
  The items in the map that was entered do not have to have been
  consumed for this to succeed.
 
- This sets thepre-order traversal cursor to the item after
+ This sets the pre-order traversal cursor to the item after
  the map that was exited.
 */
 static void QCBORDecode_ExitMap(QCBORDecodeContext *pCtx);
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index d3e4598..32d1483 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -2507,12 +2507,23 @@
 }
 
 
-
+/*
+ Public function, see header qcbor/qcbor_decode.h file
+ */
 void QCBORDecode_Rewind(QCBORDecodeContext *pMe)
 {
-   /* Reposition to search from the start of the map / array */
-   UsefulInputBuf_Seek(&(pMe->InBuf),
-                       DecodeNesting_GetMapOrArrayStart(&(pMe->nesting)));
+   size_t uResetOffset;
+
+   if(DecodeNesting_IsCurrentBounded(&(pMe->nesting))) {
+      /* Reposition to traversal cursor to the start of the map / array */
+      uResetOffset = DecodeNesting_GetMapOrArrayStart(&(pMe->nesting));
+   } else {
+      /* Reposition to traversal cursor to the start of input CBOR */
+      uResetOffset = 0ULL;
+   }
+
+   UsefulInputBuf_Seek(&(pMe->InBuf), uResetOffset);
+   pMe->uLastError = QCBOR_SUCCESS;
 }