Make tests run correcly when SIZE_MAX is less than UINT32_MAX (no change to actual implementation) (#70)

Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/test/not_well_formed_cbor.h b/test/not_well_formed_cbor.h
index efe2c33..5c6e26a 100644
--- a/test/not_well_formed_cbor.h
+++ b/test/not_well_formed_cbor.h
@@ -254,10 +254,10 @@
     {(uint8_t[]){0x41}, 1},
     // A text string is of length 1 without the 1 byte
     {(uint8_t[]){0x61}, 1},
-    // Byte string should have 2^32-15 bytes, but has one
-    {(uint8_t[]){0x5a, 0xff, 0xff, 0xff, 0xf0, 0x00}, 6},
-    // Byte string should have 2^32-15 bytes, but has one
-    {(uint8_t[]){0x7a, 0xff, 0xff, 0xff, 0xf0, 0x00}, 6},
+    // Byte string should have 65520 bytes, but has one
+    {(uint8_t[]){0x59, 0xff, 0xf0, 0x00}, 6},
+    // Byte string should have 65520 bytes, but has one
+    {(uint8_t[]){0x79, 0xff, 0xf0, 0x00}, 6},
 
 
     // Use of unassigned additional information values
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index f748104..f524849 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1663,14 +1663,15 @@
       // this test fails.
       if(!QCBORDecode_IsNotWellFormedError(uCBORError) &&
          uCBORError != QCBOR_ERR_NO_MORE_ITEMS) {
-         // Return index of failure in the error code
-         return 2000 + nIterate;
+         /* Return index of failure and QCBOR error in the result */
+         return (int32_t)(nIterate * 100 + uCBORError);
       }
    }
    return 0;
 }
 
 
+// TODO: add a test index and report it so it is eaier to figure out which test failed.
 struct FailInput {
    UsefulBufC Input;
    QCBORError nError;
@@ -1680,40 +1681,42 @@
 static int32_t ProcessFailures(struct FailInput *pFailInputs, size_t nNumFails)
 {
    for(struct FailInput *pF = pFailInputs; pF < pFailInputs + nNumFails; pF++) {
-      // Set up the decoding context including a memory pool so that
-      // indefinite length items can be checked
       QCBORDecodeContext DCtx;
-      QCBORError nCBORError;
+      QCBORError         uCBORError;
 
       QCBORDecode_Init(&DCtx, pF->Input, QCBOR_DECODE_MODE_NORMAL);
 
 #ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
+      // Set up the decoding context including a memory pool so that
+      // indefinite length items can be checked
       UsefulBuf_MAKE_STACK_UB(Pool, 100);
 
-      nCBORError = QCBORDecode_SetMemPool(&DCtx, Pool, 0);
-      if(nCBORError) {
+      uCBORError = QCBORDecode_SetMemPool(&DCtx, Pool, 0);
+      if(uCBORError) {
          return -9;
       }
 #endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
 
-
+      
       // Iterate until there is an error of some sort error
       QCBORItem Item;
       do {
          // Set to something none-zero, something other than QCBOR_TYPE_NONE
          memset(&Item, 0x33, sizeof(Item));
 
-         nCBORError = QCBORDecode_GetNext(&DCtx, &Item);
-      } while(nCBORError == QCBOR_SUCCESS);
+         uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
+      } while(uCBORError == QCBOR_SUCCESS);
+
+
 
       // Must get the expected error or the this test fails
       // The data and label type must also be QCBOR_TYPE_NONE
-      if(nCBORError != pF->nError ||
+      if(uCBORError != pF->nError ||
          Item.uDataType != QCBOR_TYPE_NONE ||
          Item.uLabelType != QCBOR_TYPE_NONE) {
          // return index of CBOR + 100
          const size_t nIndex = (size_t)(pF - pFailInputs);
-         return (int32_t)(nIndex * 100 + nCBORError);
+         return (int32_t)(nIndex * 100 + uCBORError);
       }
    }
 
@@ -1983,6 +1986,8 @@
    { {(uint8_t[]){0x41}, 1}, QCBOR_ERR_HIT_END },
    // A text string is of length 1 without the 1 byte
    { {(uint8_t[]){0x61}, 1}, QCBOR_ERR_HIT_END },
+
+#if SIZE_MAX > 2147483647
    // Byte string should have 2^32-15 bytes, but has one
    { {(uint8_t[]){0x5a, 0xff, 0xff, 0xff, 0xf0, 0x00}, 6}, QCBOR_ERR_HIT_END },
    // Byte string should have 2^32-15 bytes, but has one
@@ -1993,6 +1998,16 @@
    // Text string should have 2^64 bytes, but has 3
    { {(uint8_t[]){0x7b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                   0x01, 0x02, 0x03}, 6}, QCBOR_ERR_HIT_END },
+#else
+   // Byte string should have 2^32-15 bytes, but has one
+   { {(uint8_t[]){0x5a, 0x00, 0x00, 0xff, 0xf0, 0x00}, 6}, QCBOR_ERR_HIT_END },
+   // Byte string should have 2^32-15 bytes, but has one
+   { {(uint8_t[]){0x7a, 0x00, 0x00, 0xff, 0xf0, 0x00}, 6}, QCBOR_ERR_HIT_END },
+   // Byte string should have 2^16 bytes, but has 3
+   { {(uint8_t[]){0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x02, 0x03}, 6}, QCBOR_ERR_HIT_END },
+   // Text string should have 2^64 bytes, but has 3
+   { {(uint8_t[]){0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x02, 0x03}, 6}, QCBOR_ERR_HIT_END },
+#endif
 
    // Use of unassigned additional information values
    // Major type positive integer with reserved value 28
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index b77ba40..c7fb137 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -1781,8 +1781,9 @@
 int32_t BstrWrapErrorTest()
 {
    QCBOREncodeContext EC;
-   UsefulBufC Wrapped;
-   UsefulBufC Encoded2;
+   UsefulBufC         Wrapped;
+   UsefulBufC         Encoded2;
+   QCBORError         uError;
 
 #ifndef QCBOR_DISABLE_ENCODE_USAGE_GUARDS
    // ---- Test closing a bstrwrap when it is an array that is open ---------
@@ -1800,15 +1801,17 @@
 
    QCBOREncode_CloseArray(&EC);
 
-   if(QCBOREncode_Finish(&EC, &Encoded2) != QCBOR_ERR_CLOSE_MISMATCH) {
-      return -1;
+   uError = QCBOREncode_Finish(&EC, &Encoded2);
+   if(uError != QCBOR_ERR_CLOSE_MISMATCH) {
+      return 100 + uError;
    }
 
    // -------- test closing a bstrwrap when nothing is open ----------------
    QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
    QCBOREncode_CloseBstrWrap(&EC, &Wrapped);
-   if(QCBOREncode_Finish(&EC, &Encoded2) != QCBOR_ERR_TOO_MANY_CLOSES) {
-      return -2;
+   uError = QCBOREncode_Finish(&EC, &Encoded2);
+   if(uError != QCBOR_ERR_TOO_MANY_CLOSES) {
+      return 200 + uError;
    }
 #endif /* QCBOR_DISABLE_ENCODE_USAGE_GUARDS */
 
@@ -1823,8 +1826,9 @@
       QCBOREncode_CloseBstrWrap(&EC, &Wrapped);
    }
 
-   if(QCBOREncode_Finish(&EC, &Encoded2) != QCBOR_ERR_ARRAY_NESTING_TOO_DEEP) {
-      return -3;
+   uError = QCBOREncode_Finish(&EC, &Encoded2);
+   if(uError != QCBOR_ERR_ARRAY_NESTING_TOO_DEEP) {
+      return 300 + uError;
    }
 
    return 0;