From 0c9ba5b87ee246b772c9deb2993834f0b7fc088b Mon Sep 17 00:00:00 2001 From: Robert Falkenberg Date: Fri, 13 May 2022 16:47:52 +0200 Subject: [PATCH] lib,asn1_utils: fix out of bounds access on zero-sized array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix error: ... offset 0 is out of the bounds [0, 0] [-Werror=array-bounds] * fix note: destination object of size 0 allocated by ‘operator new []’ --> data_ = new T[cap_]; --- lib/include/srsran/asn1/asn1_utils.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/include/srsran/asn1/asn1_utils.h b/lib/include/srsran/asn1/asn1_utils.h index 87696d7b6..f1dcfcd74 100644 --- a/lib/include/srsran/asn1/asn1_utils.h +++ b/lib/include/srsran/asn1/asn1_utils.h @@ -193,8 +193,12 @@ public: { size_ = nof_items; cap_ = nof_items; - data_ = new T[cap_]; - std::copy(ptr, ptr + size_, data_); + if (ptr != NULL) { + data_ = new T[cap_]; + std::copy(ptr, ptr + size_, data_); + } else { + data_ = NULL; + } } ~dyn_array() {