Encode test coverage 100%; MAX_ITEMS_IN_MAP (#256)
Just needed a few more tests to hit 100%.
The max size of maps is now QCBOR_MAX_ITEMS_IN_MAP which is half of QCBOR_MAX_ITEMS_IN_ARRAY. This limit
was enforced for encoding, but incorrectly documented as being QCBOR_MAX_ITEMS_IN_ARRAY. The new constant
makes this clear.
The max size for decoding maps is reduced by half so it is consistent for all map use, encoding and decoding and map-decoding-as-an-array. Strictly speaking this is an incompatible change, but probably of no consequence because it went from 65,534 to 32,767 and 32,767 is still very large for a map.
Tiny encoder bug was found and fixed -- maps and arrays were limited to QCBOR_MAX_ITEMS_IN_ARRAY-1 rather than QCBOR_MAX_ITEMS_IN_ARRAY.
* Encode test coverage increased to 100%
* fix limit on map max size; test array/map max size
* straggler from last ccommit
* final clean up
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/src/qcbor_encode.c b/src/qcbor_encode.c
index 3986cbb..7657303 100644
--- a/src/qcbor_encode.c
+++ b/src/qcbor_encode.c
@@ -111,7 +111,7 @@
Nesting_Increment(QCBORTrackNesting *pNesting)
{
#ifndef QCBOR_DISABLE_ENCODE_USAGE_GUARDS
- if(1 >= QCBOR_MAX_ITEMS_IN_ARRAY - pNesting->pCurrentNesting->uCount) {
+ if(pNesting->pCurrentNesting->uCount >= QCBOR_MAX_ITEMS_IN_ARRAY) {
return QCBOR_ERR_ARRAY_TOO_LONG;
}
#endif /* ! QCBOR_DISABLE_ENCODE_USAGE_GUARDS */
@@ -223,7 +223,7 @@
*
* QCBOR_DISABLE_ENCODE_USAGE_GUARDS also disables the check for more
* than QCBOR_MAX_ITEMS_IN_ARRAY in an array. Since
- * QCBOR_MAX_ITEMS_IN_ARRAY is very large (65,535) it is very unlikely
+ * QCBOR_MAX_ITEMS_IN_ARRAY is very large (65,534) it is very unlikely
* to be reached. If it is reached, the count will wrap around to zero
* and CBOR that is not well formed will be produced, but there will
* be no buffers overrun and new security issues in the code.