mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1171603 - Better size check in nsTSubstring::ReplacePrep. r=ehsan
--HG-- extra : rebase_source : a42342c8f82cb00e1e1b9b9673fc1e290fb9cf23
This commit is contained in:
parent
db3a3881cf
commit
b6e7f5efcf
@ -4,6 +4,7 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "mozilla/CheckedInt.h"
|
||||||
#include "mozilla/double-conversion.h"
|
#include "mozilla/double-conversion.h"
|
||||||
#include "mozilla/MemoryReporting.h"
|
#include "mozilla/MemoryReporting.h"
|
||||||
|
|
||||||
@ -160,6 +161,31 @@ nsTSubstring_CharT::Finalize()
|
|||||||
// mData, mLength, and mFlags are purposefully left dangling
|
// mData, mLength, and mFlags are purposefully left dangling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nsTSubstring_CharT::ReplacePrep(index_type aCutStart,
|
||||||
|
size_type aCutLength,
|
||||||
|
size_type aNewLength)
|
||||||
|
{
|
||||||
|
aCutLength = XPCOM_MIN(aCutLength, mLength - aCutStart);
|
||||||
|
|
||||||
|
mozilla::CheckedInt<size_type> newTotalLen = mLength;
|
||||||
|
newTotalLen += aNewLength;
|
||||||
|
newTotalLen -= aCutLength;
|
||||||
|
if (!newTotalLen.isValid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aCutStart == mLength && Capacity() > newTotalLen.value()) {
|
||||||
|
mFlags &= ~F_VOIDED;
|
||||||
|
mData[newTotalLen.value()] = char_type(0);
|
||||||
|
mLength = newTotalLen.value();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ReplacePrepInternal(aCutStart, aCutLength, aNewLength,
|
||||||
|
newTotalLen.value());
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
nsTSubstring_CharT::ReplacePrepInternal(index_type aCutStart, size_type aCutLen,
|
nsTSubstring_CharT::ReplacePrepInternal(index_type aCutStart, size_type aCutLen,
|
||||||
size_type aFragLen, size_type aNewLen)
|
size_type aFragLen, size_type aNewLen)
|
||||||
|
@ -997,18 +997,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
MOZ_WARN_UNUSED_RESULT bool ReplacePrep(index_type aCutStart,
|
MOZ_WARN_UNUSED_RESULT bool ReplacePrep(index_type aCutStart,
|
||||||
size_type aCutLength,
|
size_type aCutLength,
|
||||||
size_type aNewLength)
|
size_type aNewLength);
|
||||||
{
|
|
||||||
aCutLength = XPCOM_MIN(aCutLength, mLength - aCutStart);
|
|
||||||
uint32_t newTotalLen = mLength - aCutLength + aNewLength;
|
|
||||||
if (aCutStart == mLength && Capacity() > newTotalLen) {
|
|
||||||
mFlags &= ~F_VOIDED;
|
|
||||||
mData[newTotalLen] = char_type(0);
|
|
||||||
mLength = newTotalLen;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return ReplacePrepInternal(aCutStart, aCutLength, aNewLength, newTotalLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
MOZ_WARN_UNUSED_RESULT bool NS_FASTCALL ReplacePrepInternal(
|
MOZ_WARN_UNUSED_RESULT bool NS_FASTCALL ReplacePrepInternal(
|
||||||
index_type aCutStart,
|
index_type aCutStart,
|
||||||
|
Loading…
Reference in New Issue
Block a user