From 12c0cebbbda310420a935c021014bffc2b179102 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 22 Dec 2023 17:50:15 +0100 Subject: [PATCH 2/2] EbmlUnicodeString: use std::string when reading instead of manual memory management (cherry picked from commit 6b83a0f6f6d1ae7fa14a4f96e70914c1a9686ed4) --- src/EbmlUnicodeString.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/EbmlUnicodeString.cpp b/src/EbmlUnicodeString.cpp index 56f74ce..570af17 100644 --- a/src/EbmlUnicodeString.cpp +++ b/src/EbmlUnicodeString.cpp @@ -308,24 +308,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(); } -- 2.45.1.windows.1