From 33ed4437f5b8e08b187dea9899c2752c01017ddb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 22 Dec 2023 17:50:15 +0100 Subject: [PATCH] EbmlUnicodeString: use std::string when reading instead of manual memory management --- src/EbmlUnicodeString.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/EbmlUnicodeString.cpp b/src/EbmlUnicodeString.cpp index 759ff30c..5a390c2d 100644 --- a/src/EbmlUnicodeString.cpp +++ b/src/EbmlUnicodeString.cpp @@ -226,24 +226,16 @@ filepos_t EbmlUnicodeString::ReadData(IOCallback & input, ScopeMode ReadFully) if (GetSize() == 0) { Value = static_cast(0); - SetValueIsSet(); + } else { - auto Buffer = (GetSize() + 1 < std::numeric_limits::max()) ? new (std::nothrow) char[GetSize()+1] : nullptr; - if (Buffer == nullptr) { - // impossible to read, skip it - input.setFilePointer(GetSize(), seek_current); - } else { - input.readFully(Buffer, GetSize()); - if (Buffer[GetSize()-1] != 0) { - Buffer[GetSize()] = 0; - } - - Value.SetUTF8(Buffer); // implicit conversion to std::string - delete [] Buffer; - SetValueIsSet(); - } + std::string Buffer(static_cast(GetSize()), static_cast(0)); + input.readFully(&Buffer[0], GetSize()); + + Value.SetUTF8(Buffer.c_str()); // Let conversion to std::string cut off at the first 0 } + SetValueIsSet(); + return GetSize(); }