Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EbmlString/UTFstring/EbmlUnicodeString: automatic memory management #178

Merged
merged 7 commits into from
Dec 26, 2023
26 changes: 11 additions & 15 deletions src/EbmlString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,20 @@ filepos_t EbmlString::ReadData(IOCallback & input, ScopeMode ReadFully)
return GetSize();

if (GetSize() == 0) {
Value = "";
SetValueIsSet();
Value.clear();

} else {
auto Buffer = (GetSize() + 1 < std::numeric_limits<std::size_t>::max()) ? new (std::nothrow) char[GetSize() + 1] : nullptr;
if (Buffer == nullptr) {
// unable to store the data, skip it
input.setFilePointer(GetSize(), seek_current);
} else {
input.readFully(Buffer, GetSize());
if (Buffer[GetSize()-1] != '\0') {
Buffer[GetSize()] = '\0';
}
Value = Buffer;
delete [] Buffer;
SetValueIsSet();
}
Value.resize(GetSize());
std::memset(&Value[0], 0, GetSize());
robUx4 marked this conversation as resolved.
Show resolved Hide resolved
input.readFully(&Value[0], GetSize());

auto PosNull = Value.find('\0');
if (PosNull != std::string::npos)
Value.resize(PosNull);
}

SetValueIsSet();

return GetSize();
}

Expand Down