string in the element directory can be empty

Signed-off-by: liduo <liduo29@huawei.com>
This commit is contained in:
liduo
2024-07-18 16:04:14 +08:00
parent a136bd7337
commit e5d1da21c0
+7 -1
View File
@@ -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<int8_t *>(new (nothrow) int8_t[length]);
if (buffer == nullptr) {
return false;