Bug 1595886 - Use a temp string in readSegments r=dragana

Differential Revision: https://phabricator.services.mozilla.com/D68204

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2020-04-15 12:31:34 +00:00
Родитель 2a69bde525
Коммит b5c0442d4e
1 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -305,8 +305,23 @@ nsStringInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
if (aCount > maxCount) {
aCount = maxCount;
}
nsDependentCSubstring tempData;
tempData.SetIsVoid(true);
if (mData.GetDataFlags() & nsACString::DataFlags::OWNED) {
tempData.Assign(std::move(mData));
mData.Rebind(tempData.BeginReading(), tempData.EndReading());
}
nsresult rv = aWriter(this, aClosure, mData.BeginReading() + mOffset, 0,
aCount, aResult);
if (!mData.IsVoid() && !tempData.IsVoid()) {
MOZ_DIAGNOSTIC_ASSERT(mData == tempData, "String was replaced!");
mData.SetIsVoid(true);
mData.Assign(std::move(tempData));
}
if (NS_SUCCEEDED(rv)) {
NS_ASSERTION(*aResult <= aCount,
"writer should not write more than we asked it to write");