From e5d1da21c0076f1ca14312cd05adcaced5978ba2 Mon Sep 17 00:00:00 2001 From: liduo Date: Thu, 18 Jul 2024 16:04:14 +0800 Subject: [PATCH] string in the element directory can be empty Signed-off-by: liduo --- src/resource_item.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/resource_item.cpp b/src/resource_item.cpp index 35b6391..ac87305 100644 --- a/src/resource_item.cpp +++ b/src/resource_item.cpp @@ -47,11 +47,17 @@ bool ResourceItem::SetData(const string &data) bool ResourceItem::SetData(const int8_t *data, uint32_t length) { - if (data == nullptr || length <= 0) { + if (data == nullptr || length < 0) { return false; } ReleaseData(); + if (length == 0) { + // the string in the element directory can be empty + data_ = new (nothrow) int8_t[0]; + dataLen_ = 0; + return true; + } int8_t *buffer = reinterpret_cast(new (nothrow) int8_t[length]); if (buffer == nullptr) { return false;