зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1495011. r=baku.
MozReview-Commit-ID: 8d7DzFnZx4n Differential Revision: https://phabricator.services.mozilla.com/D7273
This commit is contained in:
Родитель
033b067b5a
Коммит
2dc4ea580d
|
@ -2820,14 +2820,24 @@ ScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData,
|
|||
unicodeDecoder = WINDOWS_1252_ENCODING->NewDecoderWithoutBOMHandling();
|
||||
}
|
||||
|
||||
CheckedInt<size_t> unicodeLength =
|
||||
unicodeDecoder->MaxUTF16BufferLength(aLength);
|
||||
if (!unicodeLength.isValid()) {
|
||||
CheckedInt<size_t> maxLength = unicodeDecoder->MaxUTF16BufferLength(aLength);
|
||||
if (!maxLength.isValid()) {
|
||||
aBufOut = nullptr;
|
||||
aLengthOut = 0;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
aBufOut =
|
||||
static_cast<char16_t*>(js_malloc(unicodeLength.value() * sizeof(char16_t)));
|
||||
size_t unicodeLength = maxLength.value();
|
||||
|
||||
maxLength *= sizeof(char16_t);
|
||||
|
||||
if (!maxLength.isValid()) {
|
||||
aBufOut = nullptr;
|
||||
aLengthOut = 0;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
aBufOut = static_cast<char16_t*>(js_malloc(maxLength.value()));
|
||||
if (!aBufOut) {
|
||||
aLengthOut = 0;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -2837,11 +2847,11 @@ ScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData,
|
|||
size_t read;
|
||||
size_t written;
|
||||
bool hadErrors;
|
||||
Tie(result, read, written, hadErrors) = unicodeDecoder->DecodeToUTF16(
|
||||
data, MakeSpan(aBufOut, unicodeLength.value()), true);
|
||||
Tie(result, read, written, hadErrors) =
|
||||
unicodeDecoder->DecodeToUTF16(data, MakeSpan(aBufOut, unicodeLength), true);
|
||||
MOZ_ASSERT(result == kInputEmpty);
|
||||
MOZ_ASSERT(read == aLength);
|
||||
MOZ_ASSERT(written <= unicodeLength.value());
|
||||
MOZ_ASSERT(written <= unicodeLength);
|
||||
Unused << hadErrors;
|
||||
aLengthOut = written;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче