diff --git a/src/EbmlBinary.cpp b/src/EbmlBinary.cpp index a465c2fa..8e436c4c 100644 --- a/src/EbmlBinary.cpp +++ b/src/EbmlBinary.cpp @@ -83,25 +83,27 @@ uint64 EbmlBinary::UpdateSize(bool /* bWithDefault */, bool /* bForceRender */) filepos_t EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully) { + const auto SizeToRead = GetSize(); if (Data != nullptr) { free(Data); Data = nullptr; } if (ReadFully == SCOPE_NO_DATA) { - return GetSize(); + return SizeToRead; } - if (!GetSize()) { + if (!SizeToRead) { SetValueIsSet(); return 0; } - Data = (GetSize() < SIZE_MAX) ? static_cast(malloc(GetSize())) : nullptr; + Data = (SizeToRead < SIZE_MAX) ? static_cast(malloc(SizeToRead)) : nullptr; if (Data == nullptr) throw CRTError(std::string("Error allocating data")); + input.readFully(Data, SizeToRead); SetValueIsSet(); - return input.read(Data, GetSize()); + return SizeToRead; } bool EbmlBinary::operator==(const EbmlBinary & ElementToCompare) const