Bug 1261744 - Add two missing null checks for nsStringBuffer::Alloc(). r=erahm.

This commit is contained in:
Nicholas Nethercote
2016-04-07 09:35:50 +10:00
parent acbeab171c
commit 35455092f3
2 changed files with 14 additions and 2 deletions

View File

@@ -14,7 +14,13 @@ nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
if (buf) {
mString = static_cast<char16_t*>(buf->Data());
} else {
buf = nsStringBuffer::Alloc((mLength + 1) * sizeof(char16_t));
const size_t size = (mLength + 1) * sizeof(char16_t);
buf = nsStringBuffer::Alloc(size);
if (MOZ_UNLIKELY(!buf)) {
// We OOM because atom allocations should be small and it's hard to
// handle them more gracefully in a constructor.
NS_ABORT_OOM(size);
}
mString = static_cast<char16_t*>(buf->Data());
CopyUnicodeTo(aString, 0, mString, mLength);
mString[mLength] = char16_t(0);