Skip to content

Commit b54c8c7

Browse files
committed
Merge remote-tracking branch 'robux4/1x-fully-leak' into v1.x
2 parents 3660273 + 12c0ceb commit b54c8c7

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

src/EbmlString.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,20 @@ filepos_t EbmlString::ReadData(IOCallback & input, ScopeMode ReadFully)
142142
return GetSize();
143143

144144
if (GetSize() == 0) {
145-
Value = "";
146-
SetValueIsSet();
145+
Value.clear();
146+
147147
} else {
148-
auto Buffer = (GetSize() + 1 < std::numeric_limits<std::size_t>::max()) ? new (std::nothrow) char[GetSize() + 1] : nullptr;
149-
if (Buffer == nullptr) {
150-
// unable to store the data, skip it
151-
input.setFilePointer(GetSize(), seek_current);
152-
} else {
153-
input.readFully(Buffer, GetSize());
154-
if (Buffer[GetSize()-1] != '\0') {
155-
Buffer[GetSize()] = '\0';
156-
}
157-
Value = Buffer;
158-
delete [] Buffer;
159-
SetValueIsSet();
160-
}
148+
Value.resize(GetSize());
149+
std::memset(&Value[0], 0, GetSize());
150+
input.readFully(&Value[0], GetSize());
151+
152+
auto PosNull = Value.find('\0');
153+
if (PosNull != std::string::npos)
154+
Value.resize(PosNull);
161155
}
162156

157+
SetValueIsSet();
158+
163159
return GetSize();
164160
}
165161

src/EbmlUnicodeString.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -308,24 +308,16 @@ filepos_t EbmlUnicodeString::ReadData(IOCallback & input, ScopeMode ReadFully)
308308

309309
if (GetSize() == 0) {
310310
Value = static_cast<UTFstring::value_type>(0);
311-
SetValueIsSet();
311+
312312
} else {
313-
auto Buffer = (GetSize() + 1 < std::numeric_limits<std::size_t>::max()) ? new (std::nothrow) char[GetSize()+1] : nullptr;
314-
if (Buffer == nullptr) {
315-
// impossible to read, skip it
316-
input.setFilePointer(GetSize(), seek_current);
317-
} else {
318-
input.readFully(Buffer, GetSize());
319-
if (Buffer[GetSize()-1] != 0) {
320-
Buffer[GetSize()] = 0;
321-
}
322-
323-
Value.SetUTF8(Buffer); // implicit conversion to std::string
324-
delete [] Buffer;
325-
SetValueIsSet();
326-
}
313+
std::string Buffer(static_cast<std::string::size_type>(GetSize()), static_cast<char>(0));
314+
input.readFully(&Buffer[0], GetSize());
315+
316+
Value.SetUTF8(Buffer.c_str()); // Let conversion to std::string cut off at the first 0
327317
}
328318

319+
SetValueIsSet();
320+
329321
return GetSize();
330322
}
331323

0 commit comments

Comments
 (0)