Allow GetOutPlace to work with NULL buffers. (#155)
Previously, when used with a NULL buffer at a non-zero offset, the
UsefulOutBuf_GetOutBuf would add the offset to the null pointer and
return it to the caller. The caller would see a non-NULL buffer, but any
attempt to write to it would obviously fail.
This is fixed by returning a NULL buffer if the argument itself is NULL.
diff --git a/inc/qcbor/UsefulBuf.h b/inc/qcbor/UsefulBuf.h
index e7f4d4f..2b85833 100644
--- a/inc/qcbor/UsefulBuf.h
+++ b/inc/qcbor/UsefulBuf.h
@@ -2185,7 +2185,7 @@
UsefulBuf R;
R.len = UsefulOutBuf_RoomLeft(pUOutBuf);
- if(R.len > 0) {
+ if(R.len > 0 && pUOutBuf->UB.ptr != NULL) {
R.ptr = (uint8_t *)pUOutBuf->UB.ptr + pUOutBuf->data_len;
} else {
R.ptr = NULL;