bug fix for error handling for buffers larger than 4GB, test to verify such handling
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index dd56791..51fb5c3 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -1852,3 +1852,38 @@
return 0;
}
+
+int EncodeErrorTests()
+{
+ QCBOREncodeContext EC;
+
+ // Do all of these tests with NULL buffers as buffers would have to 4GB
+ UsefulBuf Giant = (UsefulBuf){NULL, (uint64_t)UINT32_MAX + ((uint64_t)UINT32_MAX / 2)};
+
+ // First verify no error from a really big buffer
+ QCBOREncode_Init(&EC, Giant);
+ QCBOREncode_OpenArray(&EC);
+ QCBOREncode_AddBytes(&EC, (UsefulBufC){NULL, (uint64_t)UINT32_MAX + 10000ULL});
+ QCBOREncode_CloseArray(&EC);
+ size_t xx;
+ if(QCBOREncode_FinishGetSize(&EC, &xx) != QCBOR_SUCCESS) {
+ return -1;
+ }
+
+
+ // second verify error from an array in encoded output too large
+ QCBOREncode_Init(&EC, Giant);
+ QCBOREncode_OpenArray(&EC);
+ QCBOREncode_AddBytes(&EC, (UsefulBufC){NULL, (uint64_t)UINT32_MAX+10000ULL});
+ QCBOREncode_OpenArray(&EC);
+ QCBOREncode_CloseArray(&EC);
+ QCBOREncode_CloseArray(&EC);
+ if(QCBOREncode_FinishGetSize(&EC, &xx) != QCBOR_ERR_BUFFER_TOO_LARGE) {
+ return -2;
+ }
+
+ // Need more tests for more error conditions until they are all covered exactly
+
+
+ return 0;
+}
diff --git a/test/qcbor_encode_tests.h b/test/qcbor_encode_tests.h
index 5575e10..b0674d9 100644
--- a/test/qcbor_encode_tests.h
+++ b/test/qcbor_encode_tests.h
@@ -138,6 +138,8 @@
int CoseSign1TBSTest(void);
+int EncodeErrorTests(void);
+
#endif /* defined(__QCBOR__qcbor_encode_tests__) */
diff --git a/test/run_tests.c b/test/run_tests.c
index 1090e6c..3fba941 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -153,6 +153,7 @@
TEST_ENTRY(BstrWrapErrorTest),
TEST_ENTRY(BstrWrapNestTest),
TEST_ENTRY(CoseSign1TBSTest),
+ TEST_ENTRY(EncodeErrorTests),
//TEST_ENTRY(fail_test),
};