Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/EbmlString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,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());
input.readFully(&Value[0], GetSize());

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

SetValueIsSet();

return GetSize();
}

Expand Down
22 changes: 7 additions & 15 deletions src/EbmlUnicodeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,16 @@ filepos_t EbmlUnicodeString::ReadData(IOCallback & input, ScopeMode ReadFully)

if (GetSize() == 0) {
Value = static_cast<UTFstring::value_type>(0);
SetValueIsSet();

} else {
auto Buffer = (GetSize() + 1 < std::numeric_limits<std::size_t>::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<std::string::size_type>(GetSize()), static_cast<char>(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();
}

Expand Down
Loading