Allow disabling of indefinite length array/map decoding to save object code
Allows defining of QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS to save 200 bytes of object code for the smallest decode configuration.
Added a few more tests related to bstr-wrapped CBOR.
Some code tidiness fixes (that don't change semantics)
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/QCBOR.xcodeproj/project.pbxproj b/QCBOR.xcodeproj/project.pbxproj
index 9733eb7..783af79 100644
--- a/QCBOR.xcodeproj/project.pbxproj
+++ b/QCBOR.xcodeproj/project.pbxproj
@@ -69,6 +69,19 @@
E7FDBF0E256C969D007138A8 /* cmd_line_main.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E096214AE0C700E67947 /* cmd_line_main.c */; };
E7FDBF0F256C969D007138A8 /* example.c in Sources */ = {isa = PBXBuildFile; fileRef = E743D0E124AC516D0017899F /* example.c */; };
E7FDBF10256C969D007138A8 /* UsefulBuf_Tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEBC216DE31700BA646B /* UsefulBuf_Tests.c */; };
+ E7FDBF1A257A6C1F007138A8 /* qcbor_encode.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08C214AE07400E67947 /* qcbor_encode.c */; };
+ E7FDBF1B257A6C1F007138A8 /* ieee754.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B57582161CA690080D658 /* ieee754.c */; };
+ E7FDBF1C257A6C1F007138A8 /* qcbor_err_to_str.c in Sources */ = {isa = PBXBuildFile; fileRef = E7864765252CE63100A0C11B /* qcbor_err_to_str.c */; };
+ E7FDBF1D257A6C1F007138A8 /* half_to_double_from_rfc7049.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575D2161CA7C0080D658 /* half_to_double_from_rfc7049.c */; };
+ E7FDBF1E257A6C1F007138A8 /* run_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B57632161F8F70080D658 /* run_tests.c */; };
+ E7FDBF1F257A6C1F007138A8 /* qcbor_decode.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08E214AE07500E67947 /* qcbor_decode.c */; };
+ E7FDBF20257A6C1F007138A8 /* float_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575A2161CA7C0080D658 /* float_tests.c */; };
+ E7FDBF21257A6C1F007138A8 /* qcbor_decode_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEB5216CE6CA00BA646B /* qcbor_decode_tests.c */; };
+ E7FDBF22257A6C1F007138A8 /* UsefulBuf.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08D214AE07500E67947 /* UsefulBuf.c */; };
+ E7FDBF23257A6C1F007138A8 /* qcbor_encode_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEB8216DC7AD00BA646B /* qcbor_encode_tests.c */; };
+ E7FDBF24257A6C1F007138A8 /* cmd_line_main.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E096214AE0C700E67947 /* cmd_line_main.c */; };
+ E7FDBF25257A6C1F007138A8 /* example.c in Sources */ = {isa = PBXBuildFile; fileRef = E743D0E124AC516D0017899F /* example.c */; };
+ E7FDBF26257A6C1F007138A8 /* UsefulBuf_Tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEBC216DE31700BA646B /* UsefulBuf_Tests.c */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -117,6 +130,15 @@
);
runOnlyForDeploymentPostprocessing = 1;
};
+ E7FDBF28257A6C1F007138A8 /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
@@ -157,6 +179,7 @@
E78C91E0240C90C100F4CECE /* qcbor_private.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.h; name = qcbor_private.h; path = inc/qcbor/qcbor_private.h; sourceTree = "<group>"; tabWidth = 3; };
E78C91E1240C90C100F4CECE /* qcbor_encode.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.h; name = qcbor_encode.h; path = inc/qcbor/qcbor_encode.h; sourceTree = "<group>"; tabWidth = 3; };
E7FDBF16256C969D007138A8 /* QCBOR_Disable_Indef */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = QCBOR_Disable_Indef; sourceTree = BUILT_PRODUCTS_DIR; };
+ E7FDBF2C257A6C1F007138A8 /* QCBOR_Disable_Indef_array */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = QCBOR_Disable_Indef_array; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -195,6 +218,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ E7FDBF27257A6C1F007138A8 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
@@ -230,6 +260,7 @@
E743D11B24DD4EF50017899F /* QCBOR_Disable_HW_Float */,
E743D13124DE05CC0017899F /* QCBOR_Disable_Preferred_Float */,
E7FDBF16256C969D007138A8 /* QCBOR_Disable_Indef */,
+ E7FDBF2C257A6C1F007138A8 /* QCBOR_Disable_Indef_array */,
);
name = Products;
sourceTree = "<group>";
@@ -369,6 +400,23 @@
productReference = E7FDBF16256C969D007138A8 /* QCBOR_Disable_Indef */;
productType = "com.apple.product-type.tool";
};
+ E7FDBF18257A6C1F007138A8 /* QCBOR_Disable_Indef_array */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = E7FDBF29257A6C1F007138A8 /* Build configuration list for PBXNativeTarget "QCBOR_Disable_Indef_array" */;
+ buildPhases = (
+ E7FDBF19257A6C1F007138A8 /* Sources */,
+ E7FDBF27257A6C1F007138A8 /* Frameworks */,
+ E7FDBF28257A6C1F007138A8 /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = QCBOR_Disable_Indef_array;
+ productName = QCBOR;
+ productReference = E7FDBF2C257A6C1F007138A8 /* QCBOR_Disable_Indef_array */;
+ productType = "com.apple.product-type.tool";
+ };
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@@ -401,6 +449,7 @@
E743D10924DD4EF50017899F /* QCBOR_Disable_HW_Float */,
E743D11E24DE05CC0017899F /* QCBOR_Disable_Preferred_Float */,
E7FDBF02256C969D007138A8 /* QCBOR_Disable_Indef */,
+ E7FDBF18257A6C1F007138A8 /* QCBOR_Disable_Indef_array */,
);
};
/* End PBXProject section */
@@ -503,6 +552,26 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ E7FDBF19257A6C1F007138A8 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ E7FDBF1A257A6C1F007138A8 /* qcbor_encode.c in Sources */,
+ E7FDBF1B257A6C1F007138A8 /* ieee754.c in Sources */,
+ E7FDBF1C257A6C1F007138A8 /* qcbor_err_to_str.c in Sources */,
+ E7FDBF1D257A6C1F007138A8 /* half_to_double_from_rfc7049.c in Sources */,
+ E7FDBF1E257A6C1F007138A8 /* run_tests.c in Sources */,
+ E7FDBF1F257A6C1F007138A8 /* qcbor_decode.c in Sources */,
+ E7FDBF20257A6C1F007138A8 /* float_tests.c in Sources */,
+ E7FDBF21257A6C1F007138A8 /* qcbor_decode_tests.c in Sources */,
+ E7FDBF22257A6C1F007138A8 /* UsefulBuf.c in Sources */,
+ E7FDBF23257A6C1F007138A8 /* qcbor_encode_tests.c in Sources */,
+ E7FDBF24257A6C1F007138A8 /* cmd_line_main.c in Sources */,
+ E7FDBF25257A6C1F007138A8 /* example.c in Sources */,
+ E7FDBF26257A6C1F007138A8 /* UsefulBuf_Tests.c in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
@@ -768,6 +837,35 @@
};
name = Release;
};
+ E7FDBF2A257A6C1F007138A8 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_UNDEFINED_BEHAVIOR_SANITIZER_INTEGER = YES;
+ CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
+ CODE_SIGN_STYLE = Automatic;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_PEDANTIC = YES;
+ "HEADER_SEARCH_PATHS[arch=*]" = inc;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ E7FDBF2B257A6C1F007138A8 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_UNDEFINED_BEHAVIOR_SANITIZER_INTEGER = YES;
+ CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
+ CODE_SIGN_STYLE = Automatic;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_PEDANTIC = YES;
+ "HEADER_SEARCH_PATHS[arch=*]" = inc;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@@ -825,6 +923,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
+ E7FDBF29257A6C1F007138A8 /* Build configuration list for PBXNativeTarget "QCBOR_Disable_Indef_array" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ E7FDBF2A257A6C1F007138A8 /* Debug */,
+ E7FDBF2B257A6C1F007138A8 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
/* End XCConfigurationList section */
};
rootObject = E776E074214ADF7F00E67947 /* Project object */;
diff --git a/README.md b/README.md
index 5dca649..072705b 100644
--- a/README.md
+++ b/README.md
@@ -235,8 +235,8 @@
| | smallest | largest |
|---------------|----------|---------|
| encode only | 850 | 2100 |
- | decode only | 2350 | 13500 |
- | combined | 3200 | 15600 |
+ | decode only | 2150 | 13500 |
+ | combined | 3000 | 15600 |
From the table above, one can see that the amount of code pulled in
from the QCBOR library varies a lot, ranging from 1KB to 15KB. The
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index 1dd418b..48afbf6 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -472,6 +472,10 @@
indefinite length string in the input CBOR. */
QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED = 43,
+ /** Indefinite length arrays and maps handling are disabled and there is an
+ indefinite length map or array in the input CBOR. */
+ QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED = 44,
+
/* This is stored in uint8_t; never add values > 255 */
} QCBORError;
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 77670d6..960e810 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -348,7 +348,7 @@
UsefulBufC bigNum;
} Mantissa;
} expAndMantissa;
-#endif
+#endif /* QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA */
uint64_t uTagV; // Used internally during decoding
} val;
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 9650e6a..ac59326 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -39,7 +39,7 @@
#include <math.h> // For isnan(), llround(), llroudf(), round(), roundf(),
// pow(), exp2()
#include <fenv.h> // feclearexcept(), fetestexcept()
-#endif
+#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
/*
@@ -76,6 +76,7 @@
static inline bool
QCBORItem_IsIndefiniteLengthMapOrArray(const QCBORItem *pMe)
{
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
if(!QCBORItem_IsMapOrArray(pMe)){
return false;
}
@@ -84,6 +85,10 @@
return false;
}
return true;
+#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+ (void)pMe;
+ return false;
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
}
@@ -157,15 +162,18 @@
// Not a map or array
return false;
}
+
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
if(pNesting->pCurrent->u.ma.uCountTotal == QCBOR_COUNT_INDICATES_INDEFINITE_LENGTH) {
// Is indefinite
return false;
}
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+
// All checks passed; is a definte length map or array
return true;
}
-
static inline bool
DecodeNesting_IsCurrentBstrWrapped(const QCBORDecodeNesting *pNesting)
{
@@ -768,9 +776,9 @@
// was 16 bits. It was widened to 64 bits to be passed in here.
pDecodedItem->val.dfnum = IEEE754_HalfToDouble((uint16_t)uNumber);
pDecodedItem->uDataType = QCBOR_TYPE_DOUBLE;
-#else
+#else /* QCBOR_DISABLE_PREFERRED_FLOAT */
nReturn = QCBOR_ERR_HALF_PRECISION_DISABLED;
-#endif
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
break;
case SINGLE_PREC_FLOAT: // 26
// Single precision is normally returned as a double
@@ -787,7 +795,7 @@
// In the normal case, use HW to convert float to double.
pDecodedItem->val.dfnum = (double)f;
pDecodedItem->uDataType = QCBOR_TYPE_DOUBLE;
-#else
+#else /* QCBOR_DISABLE_FLOAT_HW_USE */
// Use of float HW is disabled, return as a float.
pDecodedItem->val.fnum = f;
pDecodedItem->uDataType = QCBOR_TYPE_FLOAT;
@@ -796,7 +804,7 @@
// as a double, but it adds object code and most likely
// anyone disabling FLOAT HW use doesn't care about
// floats and wants to save object code.
-#endif
+#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
}
break;
@@ -1000,7 +1008,12 @@
goto Done;
}
if(nAdditionalInfo == LEN_IS_INDEFINITE) {
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
pDecodedItem->val.uCount = QCBOR_COUNT_INDICATES_INDEFINITE_LENGTH;
+#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+ nReturn = QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED;
+ break;
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
} else {
// type conversion OK because of check above
pDecodedItem->val.uCount = (uint16_t)uNumber;
@@ -1401,6 +1414,7 @@
}
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
/*
See if next item is a CBOR break. If it is, it is consumed,
if not it is not consumed.
@@ -1426,32 +1440,47 @@
return QCBOR_SUCCESS;
}
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
/*
- An item was just consumed, now figure out if it was the
- end of an array or map that can be closed out. That
- may in turn close out another map or array.
+ * An item was just consumed, now figure out if it was the
+ * end of an array/map map that can be closed out. That
+ * may in turn close out the above array/map...
*/
static QCBORError NestLevelAscender(QCBORDecodeContext *pMe, bool bMarkEnd)
{
QCBORError uReturn;
- /* This loops ascending nesting levels as long as there is ascending to do */
+ /* Loop ascending nesting levels as long as there is ascending to do */
while(!DecodeNesting_IsCurrentAtTop(&(pMe->nesting))) {
- if(DecodeNesting_IsCurrentDefiniteLength(&(pMe->nesting))) {
- /* Decrement count for definite length maps / arrays */
+ if(DecodeNesting_IsCurrentBstrWrapped(&(pMe->nesting))) {
+ /* Nesting level is bstr-wrapped CBOR */
+
+ /* Ascent for bstr-wrapped CBOR is always by explicit call
+ * so no further ascending can happen.
+ */
+ break;
+
+ } else if(DecodeNesting_IsCurrentDefiniteLength(&(pMe->nesting))) {
+ /* Level is a definite-length array/map */
+
+ /* Decrement the item count the definite-length array/map */
DecodeNesting_DecrementDefiniteLengthMapOrArrayCount(&(pMe->nesting));
if(!DecodeNesting_IsEndOfDefiniteLengthMapOrArray(&(pMe->nesting))) {
- /* Didn't close out map or array, so all work here is done */
+ /* Didn't close out array/map, so all work here is done */
break;
}
- /* All of a definite length array was consumed; fall through to
- ascend */
+ /* All items in a definite length array were consumed so it
+ * is time to ascend one level. This happens below.
+ */
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
} else {
- /* If not definite length, have to check for a CBOR break */
+ /* Level is an indefinite-length array/map. */
+
+ /* Check for a break which is what ends indefinite-length arrays/maps */
bool bIsBreak = false;
uReturn = NextIsBreak(&(pMe->InBuf), &bIsBreak);
if(uReturn != QCBOR_SUCCESS) {
@@ -1459,33 +1488,28 @@
}
if(!bIsBreak) {
- /* It's not a break so nothing closes out and all work is done */
+ /* Not a break so array/map does not close out. All work is done */
break;
}
- if(DecodeNesting_IsCurrentBstrWrapped(&(pMe->nesting))) {
- /*
- Break occurred inside a bstr-wrapped CBOR or
- in the top level sequence. This is always an
- error because neither are an indefinte length
- map/array.
- */
- uReturn = QCBOR_ERR_BAD_BREAK;
- goto Done;
- }
+ /* It was a break in an indefinite length map / array so
+ * it is time to ascend one level.
+ */
- /* It was a break in an indefinite length map / array */
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
}
- /* All items in the map/array level have been consumed. */
+
+ /* All items in the array/map have been consumed. */
/* But ascent in bounded mode is only by explicit call to
- QCBORDecode_ExitBoundedMode() */
+ * QCBORDecode_ExitBoundedMode().
+ */
if(DecodeNesting_IsCurrentBounded(&(pMe->nesting))) {
/* Set the count to zero for definite length arrays to indicate
- cursor is at end of bounded map / array */
+ * cursor is at end of bounded array/map */
if(bMarkEnd) {
- // Used for definite and indefinite to signal end
+ /* Used for definite and indefinite to signal end */
DecodeNesting_ZeroMapOrArrayCount(&(pMe->nesting));
}
@@ -1498,7 +1522,10 @@
uReturn = QCBOR_SUCCESS;
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
Done:
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+
return uReturn;
}
@@ -1561,15 +1588,15 @@
/*
Check to see if at the end of a bounded definite length map or
- array. The check for the end of an indefinite length array is
- later.
+ array. The check for a break ending indefinite length array is
+ later in NestLevelAscender().
*/
if(DecodeNesting_IsAtEndOfBoundedLevel(&(me->nesting))) {
uReturn = QCBOR_ERR_NO_MORE_ITEMS;
goto Done;
}
- /* ==== Next: not at the end so get another item ==== */
+ /* ==== Next: not at the end, so get another item ==== */
uReturn = GetNext_MapEntry(me, pDecodedItem);
if(QCBORDecode_IsUnrecoverableError(uReturn)) {
/* Error is so bad that traversal is not possible. */
@@ -1577,8 +1604,8 @@
}
/*
- Breaks ending arrays/maps are always processed at the end of this
- function. They should never show up here.
+ Breaks ending arrays/maps are processed later in the call to
+ NestLevelAscender(). They should never show up here.
*/
if(pDecodedItem->uDataType == QCBOR_TYPE_BREAK) {
uReturn = QCBOR_ERR_BAD_BREAK;
@@ -1623,7 +1650,7 @@
QCBORItem_IsIndefiniteLengthMapOrArray(pDecodedItem)) {
/*
The following cases are handled here:
- - A non-aggregate like an integer or string
+ - A non-aggregate item like an integer or string
- An empty definite length map or array
- An indefinite length map or array that might be empty or might not.
@@ -4528,7 +4555,7 @@
return QCBOR_ERR_UNEXPECTED_TYPE;
}
break;
-#endif
+#endif /* QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA */
default:
return QCBOR_ERR_UNEXPECTED_TYPE;
}
@@ -4634,9 +4661,9 @@
return QCBOR_ERR_UNEXPECTED_TYPE;
}
}
-#else
+#else /* QCBOR_DISABLE_FLOAT_HW_USE */
return QCBOR_ERR_HW_FLOAT_DISABLED;
-#endif
+#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
break;
case QCBOR_TYPE_DOUBLE:
diff --git a/src/qcbor_encode.c b/src/qcbor_encode.c
index e04e21b..c0ca257 100644
--- a/src/qcbor_encode.c
+++ b/src/qcbor_encode.c
@@ -467,7 +467,7 @@
if(pBufferEnd - pByte > 9 || pBufferEnd - pByte < 1 || pByte < (uint8_t *)buffer.ptr) {
return NULLUsefulBufC;
}
-#endif
+#endif /* EXTRA_ENCODE_HEAD_CHECK */
/* Length will not go negative because the loops run for at most 8 decrements
* of pByte, only one other decrement is made, and the array is sized
@@ -702,9 +702,9 @@
const IEEE754_union uNum = IEEE754_DoubleToSmallest(dNum);
QCBOREncode_AddType7(me, uNum.uSize, uNum.uValue);
-#else
+#else /* QCBOR_DISABLE_PREFERRED_FLOAT */
QCBOREncode_AddDoubleNoPreferred(me, dNum);
-#endif
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
}
@@ -728,9 +728,9 @@
const IEEE754_union uNum = IEEE754_FloatToSmallest(fNum);
QCBOREncode_AddType7(me, uNum.uSize, uNum.uValue);
-#else
+#else /* QCBOR_DISABLE_PREFERRED_FLOAT */
QCBOREncode_AddFloatNoPreferred(me, fNum);
-#endif
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
}
@@ -900,9 +900,9 @@
return;
}
}
-#else
+#else /* QCBOR_DISABLE_ENCODE_USAGE_GUARDS */
(void) uMajorType;
-#endif
+#endif /* QCBOR_DISABLE_ENCODE_USAGE_GUARDS */
/* Append the break marker (0xff for both arrays and maps) */
AppendCBORHead(me, CBOR_MAJOR_NONE_TYPE_SIMPLE_BREAK, CBOR_SIMPLE_BREAK, 0);
@@ -926,7 +926,7 @@
uReturn = QCBOR_ERR_ARRAY_OR_MAP_STILL_OPEN;
goto Done;
}
-#endif
+#endif /* QCBOR_DISABLE_ENCODE_USAGE_GUARDS */
*pEncodedCBOR = UsefulOutBuf_OutUBuf(&(me->OutBuf));
diff --git a/test/float_tests.c b/test/float_tests.c
index 3f8ec1a..12f34fd 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -1182,4 +1182,4 @@
return 0;
}
-#endif
+#endif /* NAN_EXPERIMENT */
diff --git a/test/not_well_formed_cbor.h b/test/not_well_formed_cbor.h
index 5c6e26a..6734e93 100644
--- a/test/not_well_formed_cbor.h
+++ b/test/not_well_formed_cbor.h
@@ -26,9 +26,9 @@
static const struct someBinaryBytes paNotWellFormedCBOR[] = {
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
// Indefinite length strings must be closed off
-#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
// An indefinite length byte string not closed off
{(uint8_t[]){0x5f, 0x41, 0x00}, 3},
// An indefinite length text string not closed off
@@ -76,6 +76,7 @@
{(uint8_t[]){0xa2, 0x01, 0x02}, 3},
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// Indefinte length maps and arrays must be ended by a break
// Indefinite length array with zero items and no break
@@ -102,6 +103,7 @@
{(uint8_t[]){0x9f, 0x81, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff}, 9},
// Mixed nesting with definite unclosed
{(uint8_t[]){0x9f, 0x82, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 10},
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
// The "argument" for the data item is missing bytes
@@ -165,8 +167,10 @@
{(uint8_t[]){0xff}, 1},
// A bare break after a zero length definite length array
{(uint8_t[]){0x80, 0xff}, 2},
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// A bare break after a zero length indefinite length map
{(uint8_t[]){0x9f, 0xff, 0xff}, 3},
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
// Forbidden two-byte encodings of simple types
@@ -318,10 +322,12 @@
{(uint8_t[]){0xa1, 0x00}, 2},
// Map with 3 item when it should have 4
{(uint8_t[]){0xa2, 0x00, 0x00, 0x00}, 2},
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// Map with 1 item when it should have 2
{(uint8_t[]){0xbf, 0x00, 0xff}, 3},
// Map with 3 item when it should have 4
{(uint8_t[]){0xbf, 0x00, 0x00, 0x00, 0xff}, 5},
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
};
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index f524849..f78ee8d 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -60,7 +60,7 @@
fflush(stdout);
}
-#endif
+#endif /* PRINT_FUNCTIONS_FOR_DEBUGGING */
static const uint8_t spExpectedEncodedInts[] = {
@@ -544,6 +544,8 @@
0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63,
0x73 };
+
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// Same as above, but with indefinite lengths.
static const uint8_t pValidMapIndefEncoded[] = {
0xbf, 0x6d, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x69, 0x6e,
@@ -562,6 +564,7 @@
0x6e, 0x20, 0x6c, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64,
0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63,
0x73, 0xff, 0xff};
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
static int32_t ParseOrderedArray(const uint8_t *pEncoded,
@@ -677,6 +680,7 @@
static uint8_t sEmpties[] = {0x83, 0x00, 0x80, 0x84, 0x80, 0x81, 0x00, 0xa0,
0xa3, 0x01, 0xa0, 0x02, 0xa0, 0x03, 0x80};
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
/* Same as above, but with indefinte lengths */
static uint8_t sEmptiesIndef[] = {
0x9F,
@@ -704,7 +708,7 @@
0xFF,
0xFF,
0xFF};
-
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
static int32_t CheckEmpties(UsefulBufC input, bool bCheckCounts)
@@ -840,12 +844,14 @@
return nResult;
}
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
nResult = CheckEmpties(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(sEmptiesIndef),
false);
if(nResult) {
return nResult -100;
}
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
return 0;
}
@@ -1801,7 +1807,7 @@
// A definte length map that is supposed to have s item, but has only 1
{ {(uint8_t[]){0xa2, 0x01, 0x02}, 3}, QCBOR_ERR_NO_MORE_ITEMS },
-
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// Indefinte length maps and arrays must be ended by a break
// Indefinite length array with zero items and no break
{ {(uint8_t[]){0x9f}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
@@ -1844,7 +1850,7 @@
{ {(uint8_t[]){0x81, 0x82, 0xbf, 0xff, 0xbf}, 5}, QCBOR_ERR_NO_MORE_ITEMS},
// Unclosed definite length map in indefinite length arrays
{ {(uint8_t[]){0x9f, 0x9f, 0xa1}, 3}, QCBOR_ERR_NO_MORE_ITEMS},
-
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
// The "argument" for the data item is incomplete
// Positive integer missing 1 byte argument
@@ -1908,12 +1914,14 @@
{ {(uint8_t[]){0xff}, 1}, QCBOR_ERR_BAD_BREAK },
// A bare break after a zero length definite length array
{ {(uint8_t[]){0x80, 0xff}, 2}, QCBOR_ERR_BAD_BREAK },
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// A bare break after a zero length indefinite length map
{ {(uint8_t[]){0x9f, 0xff, 0xff}, 3}, QCBOR_ERR_BAD_BREAK },
// A break inside a definite length array inside an indefenite length array
{ {(uint8_t[]){0x9f, 0x81, 0xff}, 3}, QCBOR_ERR_BAD_BREAK },
// Complicated mixed nesting with break outside indefinite length array
{ {(uint8_t[]){0x9f, 0x82, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 10}, QCBOR_ERR_BAD_BREAK },
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
// Forbidden two byte encodings of simple types
@@ -2065,10 +2073,12 @@
{ {(uint8_t[]){0xa1, 0x00}, 2}, QCBOR_ERR_HIT_END },
// Map with 3 item when it should have 4
{ {(uint8_t[]){0xa2, 0x00, 0x00, 0x00}, 2}, QCBOR_ERR_HIT_END },
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// Map with 1 item when it should have 2
{ {(uint8_t[]){0xbf, 0x00, 0xff}, 3}, QCBOR_ERR_BAD_BREAK },
// Map with 3 item when it should have 4
{ {(uint8_t[]){0xbf, 0x00, 0x00, 0x00, 0xff}, 5}, QCBOR_ERR_BAD_BREAK },
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
// In addition to not-well-formed, some invalid CBOR
@@ -2374,9 +2384,9 @@
if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_HALF_PRECISION_DISABLED) {
return -18;
}
-#endif
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
-#else
+#else /* QCBOR_DISABLE_FLOAT_HW_USE */
if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_FLOAT_DATE_DISABLED) {
return -19;
}
@@ -2403,9 +2413,9 @@
if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_HALF_PRECISION_DISABLED) {
return -26;
}
-#endif
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
-#endif
+#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
return 0;
}
@@ -2438,7 +2448,7 @@
Untagged values
*/
-static uint8_t spSpiffyDateTestInput[] = {
+static const uint8_t spSpiffyDateTestInput[] = {
0x86,
0xc1,
@@ -2451,12 +2461,12 @@
0xf9, 0xfc, 0x00, // Half-precision -Infinity
0xc1, // tag for epoch date
- 0x9f, 0xff, // Erroneous empty array as content for date
+ 0x80, // Erroneous empty array as content for date
0xc0, // tag for string date
- 0xbf, 0xff, // Erroneous empty map as content for date
+ 0xa0, // Erroneous empty map as content for date
- 0xbf, // Open a map for tests involving labels.
+ 0xa9, // Open a map for tests involving labels.
0x00,
0xc0, // tag for string date
@@ -2495,8 +2505,6 @@
// Untagged half-precision float with value -2
0x09,
0xF9, 0xC0, 0x00,
-
- 0xff,
};
int32_t SpiffyDateDecodeTest()
@@ -2525,7 +2533,7 @@
if(uError != QCBOR_ERR_FLOAT_DATE_DISABLED) {
return 1112;
}
-#endif
+#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
// Too-large integer
QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
@@ -2862,7 +2870,7 @@
static uint8_t spSpiffyTagInput[] = {
- 0x9f, // Open indefinite array
+ 0x85, // Open array
0xc0, // tag for string date
0x6a, '1','9','8','5','-','0','4','-','1','2', // Date string
@@ -2876,8 +2884,6 @@
0xc0, // tag for string date
0x4a, '1','9','8','5','-','0','4','-','1','2', // Date string in byte string
-
- 0xff
};
@@ -2927,7 +2933,7 @@
uError = QCBORDecode_GetNext(&DCtx, &Item);
uError = QCBORDecode_GetNext(&DCtx, &Item);
-#else
+#else /* QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA */
if(uError != QCBOR_SUCCESS ||
Item.uDataType != QCBOR_TYPE_DECIMAL_FRACTION ||
QCBORDecode_GetNthTag(&DCtx, &Item, 0) != CBOR_TAG_INVALID64 ||
@@ -2937,7 +2943,7 @@
QCBORDecode_GetNthTag(&DCtx, &Item, 4) != CBOR_TAG_INVALID64 ) {
return -5;
}
-#endif
+#endif /* QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA */
/*
More than 4 tags on an item 225(226(227(228(229([])))))
@@ -4655,8 +4661,13 @@
{ {(uint8_t[]){0xC4, 0x82, 0x1f, 0x01}, 4}, QCBOR_ERR_BAD_INT},
// 3 items in array
{ {(uint8_t[]){0xC4, 0x83, 0x03, 0x01, 02}, 5}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// unterminated indefinite length array
{ {(uint8_t[]){0xC4, 0x9f, 0x03, 0x01, 0x02}, 5}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
+#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+ // unterminated indefinite length array
+ { {(uint8_t[]){0xC4, 0x9f, 0x03, 0x01, 0x02}, 5}, QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED},
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
// Empty array
{ {(uint8_t[]){0xC4, 0x80}, 2}, QCBOR_ERR_NO_MORE_ITEMS},
// Second is not an integer
@@ -4973,12 +4984,16 @@
0x48, 0x67, 0x61, 0x6C, 0x61, 0x63, 0x74, 0x69, 0x63,
0x4B, 0x68, 0x61, 0x76, 0x65, 0x6E, 0x20, 0x74, 0x6F, 0x6B, 0x65, 0x6E};
+static const uint8_t spArrayOfEmpty[] = {0x84, 0x40, 0xa0, 0x80, 0x00};
+
static const uint8_t spEmptyMap[] = {0xa0};
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
static const uint8_t spEmptyInDefinteLengthMap[] = {0xbf, 0xff};
-static const uint8_t spArrayOfEmpty[] = {0x84, 0x40, 0xa0, 0x80, 0x00};
+
+
/*
{
@@ -5006,6 +5021,9 @@
0x80, 0x02, 0xa0, 0x03, 0x80, 0x04, 0xa0, 0x05, 0x9f, 0xff,
0x06, 0x9f, 0x80, 0x9f, 0xff, 0xff};
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+
+
/*
Too many tags
Invalid tag content
@@ -5020,7 +5038,7 @@
5: 0, 8: 8}
*/
static const uint8_t spRecoverableMapErrors[] = {
- 0xbf,
+ 0xa7,
0x01, 0xd8, 0xe0, 0xd8, 0xe1, 0xd8, 0xe2, 0xd8, 0xe3, 0xd8, 0x04, 0x00,
0x02, 0xc1, 0x40,
0x03, 0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -5028,7 +5046,6 @@
0x05, 0x00,
0x05, 0x00,
0x08, 0x08,
- 0xff
};
// Bad break
@@ -5036,6 +5053,7 @@
0xa2, 0xff, 0x01, 0x00, 0x02, 0x00
};
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
// No more items
static const uint8_t spUnRecoverableMapError2[] = {
0xbf, 0x02, 0xbf, 0xff, 0x01, 0x00, 0x02, 0x00
@@ -5055,6 +5073,7 @@
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff
};
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
int32_t EnterMapTest()
@@ -5065,7 +5084,7 @@
int32_t nReturn;
QCBORError uErr;
-
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spMapOfEmpty), 0);
QCBORDecode_EnterMap(&DCtx, NULL);
@@ -5109,12 +5128,13 @@
return 3011;
}
-
(void)pValidMapIndefEncoded;
nReturn = SpiffyDecodeBasicMap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapIndefEncoded));
if(nReturn) {
return nReturn + 20000;
}
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+
nReturn = SpiffyDecodeBasicMap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded));
if(nReturn) {
@@ -5227,6 +5247,7 @@
}
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEmptyInDefinteLengthMap), 0);
QCBORDecode_EnterMap(&DCtx, NULL);
// This will fail because the map is empty.
@@ -5240,6 +5261,7 @@
if(uErr != QCBOR_SUCCESS){
return 2013;
}
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spArrayOfEmpty), 0);
@@ -5292,7 +5314,7 @@
if(uErr != QCBOR_ERR_FLOAT_DATE_DISABLED) {
return 2027;
}
-#endif
+#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
QCBORDecode_GetInt64InMapN(&DCtx, 0x05, &nInt);
uErr = QCBORDecode_GetAndResetError(&DCtx);
@@ -5316,6 +5338,7 @@
return 2030;
}
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spUnRecoverableMapError2), 0);
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetInt64InMapN(&DCtx, 0x01, &nInt);
@@ -5339,6 +5362,8 @@
if(uErr != QCBOR_ERR_ARRAY_DECODE_NESTING_TOO_DEEP) {
return 2033;
}
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+
nReturn = DecodeNestedIterate();
@@ -5624,7 +5649,7 @@
-4.0,
QCBOR_SUCCESS // Uses ieee754.h to conver, not HW
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
-#else
+#else /* QCBOR_DISABLE_PREFERRED_FLOAT */
// Half-precision disabled
-4,
QCBOR_ERR_HALF_PRECISION_DISABLED,
@@ -5632,7 +5657,7 @@
QCBOR_ERR_HALF_PRECISION_DISABLED,
-4.0,
QCBOR_ERR_HALF_PRECISION_DISABLED
-#endif
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
},
{
"Decimal fraction 3/10",
@@ -6028,6 +6053,7 @@
// Get a second item
uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
if(uCBORError != QCBOR_SUCCESS) {
return 9;
}
@@ -6041,6 +6067,11 @@
if(uCBORError != QCBOR_ERR_ARRAY_OR_MAP_UNCONSUMED) {
return 11;
}
+#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+ if(uCBORError != QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED) {
+ return 20;
+ }
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
// --- Sequence with a closed indefinite length array ---
@@ -6061,6 +6092,8 @@
// Get a second item
uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
+
if(uCBORError != QCBOR_SUCCESS) {
return 14;
}
@@ -6074,6 +6107,11 @@
if(uCBORError != QCBOR_SUCCESS) {
return 16;
}
+#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+ if(uCBORError != QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED) {
+ return 20;
+ }
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
return 0;
@@ -6329,6 +6367,10 @@
return Encoded;
}
+static const uint8_t spBreakInByteString[] = {
+ 0x41, 0xff
+};
+
int32_t EnterBstrTest()
{
@@ -6363,8 +6405,43 @@
QCBORDecode_ExitArray(&DC);
QCBORError uErr = QCBORDecode_Finish(&DC);
+ if(uErr) {
+ return (int32_t)uErr;
+ }
- return (int32_t)uErr;
+
+ /* Enter and exit byte string wrapped CBOR that is bad. It has just a break.
+ * Successful because no items are fetched from byte string.
+ */
+ QCBORDecode_Init(&DC,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBreakInByteString),
+ 0);
+ QCBORDecode_EnterBstrWrapped(&DC, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL);
+ uErr = QCBORDecode_GetError(&DC);
+ if(uErr) {
+ return 100 + (int32_t)uErr;
+ }
+
+ QCBORDecode_ExitBstrWrapped(&DC);
+ uErr = QCBORDecode_GetError(&DC);
+ if(uErr) {
+ return 200 + (int32_t)uErr;
+ }
+
+ /* Try to get item that is a break out of a byte string wrapped CBOR.
+ * It fails because there should be no break.
+ */
+ QCBORDecode_Init(&DC,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBreakInByteString),
+ 0);
+ QCBORDecode_EnterBstrWrapped(&DC, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL);
+ QCBORItem Item;
+ uErr = QCBORDecode_GetNext(&DC, &Item);
+ if(uErr != QCBOR_ERR_BAD_BREAK) {
+ return 300 + (int32_t)uErr;
+ }
+
+ return 0;
}
@@ -6748,7 +6825,7 @@
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
static const uint8_t spMapWithIndefLenStrings[] = {
- 0xbf,
+ 0xa3,
0x7f, 0x61, 'l', 0x64, 'a', 'b', 'e', 'l' , 0x61, '1', 0xff,
0x5f, 0x42, 0x01, 0x02, 0x43, 0x03, 0x04, 0x05, 0xff,
0x7f, 0x62, 'd', 'y', 0x61, 'm', 0x61, 'o', 0xff,
@@ -6756,7 +6833,6 @@
0x7f, 0x62, 'l', 'a', 0x63, 'b', 'e', 'l', 0x61, '2', 0xff,
0xc3,
0x5f, 0x42, 0x00, 0x01, 0x42, 0x00, 0x01, 0x41, 0x01, 0xff,
- 0xff
};
int32_t SpiffyIndefiniteLengthStringsTests()
@@ -6803,11 +6879,11 @@
if(uDouble != -16777474) {
return 6;
}
-#else
+#else /* QCBOR_DISABLE_FLOAT_HW_USE */
if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_HW_FLOAT_DISABLED) {
return 7;
}
-#endif
+#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
QCBORDecode_ExitMap(&DCtx);
diff --git a/test/run_tests.c b/test/run_tests.c
index b2dc46c..0146d93 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -63,8 +63,11 @@
TEST_ENTRY(EmptyMapsAndArraysTest),
TEST_ENTRY(NotWellFormedTests),
TEST_ENTRY(ParseMapAsArrayTest),
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
TEST_ENTRY(IndefiniteLengthNestTest),
+ TEST_ENTRY(IndefiniteLengthArrayMapTest),
TEST_ENTRY(NestedMapTestIndefLen),
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
TEST_ENTRY(ParseSimpleTest),
TEST_ENTRY(DecodeFailureTests),
TEST_ENTRY(EncodeRawTest),
@@ -82,7 +85,6 @@
TEST_ENTRY(ParseTooDeepArrayTest),
TEST_ENTRY(ComprehensiveInputTest),
TEST_ENTRY(ParseMapTest),
- TEST_ENTRY(IndefiniteLengthArrayMapTest),
TEST_ENTRY(BasicEncodeTest),
TEST_ENTRY(NestedMapTest),
TEST_ENTRY(BignumParseTest),