Make OpenBytes call OpenMapOrArray even if the buffer is NULL. (#156)
It's not clear to me was the call was wrapped in this condition, but
since OpenMapOrArray is responsible for recording nesting information,
this broke any OpenBytes/CloseBytes that were designed to work with both
NULL and non-NULL buffers.
diff --git a/src/qcbor_encode.c b/src/qcbor_encode.c
index 3a0a968..26d86ce 100644
--- a/src/qcbor_encode.c
+++ b/src/qcbor_encode.c
@@ -986,18 +986,16 @@
void QCBOREncode_OpenBytes(QCBOREncodeContext *pMe, UsefulBuf *pPlace)
{
*pPlace = UsefulOutBuf_GetOutPlace(&(pMe->OutBuf));
- if(!UsefulBuf_IsNULL(*pPlace)) {
#ifndef QCBOR_DISABLE_ENCODE_USAGE_GUARDS
- // TODO: is this right?
- uint8_t uMajorType = Nesting_GetMajorType(&(pMe->nesting));
- if(uMajorType == CBOR_MAJOR_NONE_TYPE_OPEN_BSTR) {
- pMe->uError = QCBOR_ERR_OPEN_BYTE_STRING;
- return;
- }
+ // TODO: is this right?
+ uint8_t uMajorType = Nesting_GetMajorType(&(pMe->nesting));
+ if(uMajorType == CBOR_MAJOR_NONE_TYPE_OPEN_BSTR) {
+ pMe->uError = QCBOR_ERR_OPEN_BYTE_STRING;
+ return;
+ }
#endif /* QCBOR_DISABLE_ENCODE_USAGE_GUARDS */
- QCBOREncode_OpenMapOrArray(pMe, CBOR_MAJOR_NONE_TYPE_OPEN_BSTR);
- }
+ QCBOREncode_OpenMapOrArray(pMe, CBOR_MAJOR_NONE_TYPE_OPEN_BSTR);
}