fix test for error out on max length strings
diff --git a/inc/qcbor/qcbor_encode.h b/inc/qcbor/qcbor_encode.h
index 8f4f1cf..3b92943 100644
--- a/inc/qcbor/qcbor_encode.h
+++ b/inc/qcbor/qcbor_encode.h
@@ -1773,14 +1773,14 @@
@param uMinLen The minimum number of bytes to encode uNumber. Almost always
this is 0 to use preferred minimal encoding. If this is 4,
then even the values 0xffff and smaller will be encoded
- as in 4 bytes. This is used primarily when encoding a
+ in 4 bytes. This is used primarily when encoding a
float or double put into uNumber as the leading zero bytes
for them must be encoded.
@param uNumber The numeric argument part of the CBOR head.
@return Pointer and length of the encoded head or
@NULLUsefulBufC if the output buffer is too small.
- Callers to need to call this for normal CBOR encoding. Note that it doesn't even
+ Callers do not to need to call this for normal CBOR encoding. Note that it doesn't even
take a @ref QCBOREncodeContext argument.
This encodes the major type and argument part of a data item. The
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 71bde05..49cf76a 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -2023,29 +2023,30 @@
return -2;
}
-/*
- TODO: fix this
- This test is disabled until QCBOREncode_EncodeHead() is brought in so
- the size encoded can be tied to SIZE_MAX and work for all size CPUs.
- This relies on the largest string allowed being SIZE_MAX -4 rather than
- SIZE_MAX. That way the test can be performed.
- {
- QCBORDecodeContext DCtx;
- QCBORItem Item;
+ /*
+ The max size of a string for QCBOR is SIZE_MAX - 4 so this
+ tests here can be performed to see that the max length
+ error check works correctly. See DecodeBytes(). If the max
+ size was SIZE_MAX, it wouldn't be possible to test this.
- static uint8_t foo[] = {0x5b, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff};
+ This test will automatocally adapt the all CPU sizes
+ through the use of SIZE_MAX.
+ */
- QCBORDecode_Init(&DCtx,
- UsefulBuf_FROM_BYTE_ARRAY_LITERAL(foo),
- QCBOR_DECODE_MODE_NORMAL);
+ MakeUsefulBufOnStack( HeadBuf, QCBOR_HEAD_BUFFER_SIZE);
+ UsefulBufC EncodedHead;
- if(QCBOR_ERR_STRING_TOO_LONG != QCBORDecode_GetNext(&DCtx, &Item)) {
- return -4;
- }
+ // This makes a CBOR head with a text string that is very long
+ // but doesn't fill in the bytes of the text string as that is
+ // not needed to test this part of QCBOR.
+ EncodedHead = QCBOREncode_EncodeHead(HeadBuf, CBOR_MAJOR_TYPE_TEXT_STRING, 0, SIZE_MAX);
+
+ QCBORDecode_Init(&DCtx, EncodedHead, QCBOR_DECODE_MODE_NORMAL);
+
+ if(QCBOR_ERR_STRING_TOO_LONG != QCBORDecode_GetNext(&DCtx, &Item)) {
+ return -4;
}
-*/
return 0;
}