Fix static analyzer warnings for adding empty data/strings (#170)
CBOR allows empty text and byte strings and QBOR supports them with AddText() and AddBytes() with a size of zero.
This results in a call to memmove with a NULL pointer. It was always with a zero length. Implementations of memmove tolerate this, but it is not recommended and static analyzers complain.
This PR fixes this. It also adds tests for this condition. It also documents that adding strings of zero length is supported in UsefulBuf.
This addresses #164
* Correct support for adding empty text/byte strings
* Update change log
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/inc/qcbor/UsefulBuf.h b/inc/qcbor/UsefulBuf.h
index e1b3146..aa24507 100644
--- a/inc/qcbor/UsefulBuf.h
+++ b/inc/qcbor/UsefulBuf.h
@@ -42,6 +42,7 @@
when who what, where, why
-------- ---- --------------------------------------------------
+ 19/12/2022 llundblade Document that adding empty data is allowed.
4/11/2022 llundblade Add GetOutPlace and Advance to UsefulOutBuf.
9/21/2021 llundbla Clarify UsefulOutBuf size calculation mode
8/8/2021 dthaler/llundbla Work with C++ without compiler extensions
@@ -947,6 +948,8 @@
* Overlapping buffers are OK. @c NewData can point to data in the
* output buffer.
*
+ * NewData.len may be 0 in which case nothing will be inserted.
+ *
* If an error occurs, an error state is set in the @ref
* UsefulOutBuf. No error is returned. All subsequent attempts to add
* data will do nothing.