mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1097283: Fix count/byte mismatches in NS_ABORT_OOM calls. r=froydnj
--HG-- extra : rebase_source : a9f4ae9e6f05e5ade56b741fa2f110974c5f08ac
This commit is contained in:
parent
dbf184c18a
commit
2443f0a5f3
@ -126,7 +126,7 @@ public:
|
||||
*/
|
||||
void AppendTo(nsAString& aString) const {
|
||||
if (!AppendTo(aString, mozilla::fallible_t())) {
|
||||
NS_ABORT_OOM(GetLength());
|
||||
aString.AllocFailed(aString.Length() + GetLength());
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ public:
|
||||
*/
|
||||
void AppendTo(nsAString& aString, int32_t aOffset, int32_t aLength) const {
|
||||
if (!AppendTo(aString, aOffset, aLength, mozilla::fallible_t())) {
|
||||
NS_ABORT_OOM(aLength);
|
||||
aString.AllocFailed(aString.Length() + aLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ public:
|
||||
void Push(void* aItem)
|
||||
{
|
||||
if (!Push(aItem, fallible_t())) {
|
||||
NS_ABORT_OOM(mSize);
|
||||
NS_ABORT_OOM(mSize * sizeof(void*));
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ public:
|
||||
void PushFront(void* aItem)
|
||||
{
|
||||
if (!PushFront(aItem, fallible_t())) {
|
||||
NS_ABORT_OOM(mSize);
|
||||
NS_ABORT_OOM(mSize * sizeof(void*));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ void
|
||||
AppendASCIItoUTF16(const nsACString& aSource, nsAString& aDest)
|
||||
{
|
||||
if (!AppendASCIItoUTF16(aSource, aDest, mozilla::fallible_t())) {
|
||||
NS_ABORT_OOM(aDest.Length() + aSource.Length());
|
||||
aDest.AllocFailed(aDest.Length() + aSource.Length());
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ void
|
||||
AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest)
|
||||
{
|
||||
if (!AppendUTF16toUTF8(aSource, aDest, mozilla::fallible_t())) {
|
||||
NS_ABORT_OOM(aDest.Length() + aSource.Length());
|
||||
aDest.AllocFailed(aDest.Length() + aSource.Length());
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ void
|
||||
AppendUTF8toUTF16(const nsACString& aSource, nsAString& aDest)
|
||||
{
|
||||
if (!AppendUTF8toUTF16(aSource, aDest, mozilla::fallible_t())) {
|
||||
NS_ABORT_OOM(aDest.Length() + aSource.Length());
|
||||
aDest.AllocFailed(aDest.Length() + aSource.Length());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -919,7 +919,7 @@ void
|
||||
nsString::ReplaceChar( const char16_t* aSet, char16_t aNewChar )
|
||||
{
|
||||
if (!EnsureMutable()) // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
|
||||
char16_t* data = mData;
|
||||
uint32_t lenRemaining = mLength;
|
||||
|
@ -386,7 +386,7 @@ nsTString_CharT::SetCharAt( char16_t aChar, uint32_t aIndex )
|
||||
return false;
|
||||
|
||||
if (!EnsureMutable())
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
|
||||
mData[aIndex] = CharT(aChar);
|
||||
return true;
|
||||
@ -401,7 +401,7 @@ void
|
||||
nsTString_CharT::StripChars( const char* aSet )
|
||||
{
|
||||
if (!EnsureMutable())
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
|
||||
mLength = nsBufferRoutines<CharT>::strip_chars(mData, mLength, aSet);
|
||||
}
|
||||
@ -421,7 +421,7 @@ void
|
||||
nsTString_CharT::ReplaceChar( char_type aOldChar, char_type aNewChar )
|
||||
{
|
||||
if (!EnsureMutable()) // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
|
||||
for (uint32_t i=0; i<mLength; ++i)
|
||||
{
|
||||
@ -434,7 +434,7 @@ void
|
||||
nsTString_CharT::ReplaceChar( const char* aSet, char_type aNewChar )
|
||||
{
|
||||
if (!EnsureMutable()) // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
|
||||
char_type* data = mData;
|
||||
uint32_t lenRemaining = mLength;
|
||||
|
@ -263,7 +263,7 @@ void
|
||||
nsTSubstring_CharT::Assign(char_type aChar)
|
||||
{
|
||||
if (!ReplacePrep(0, mLength, 1)) {
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
|
||||
*mData = aChar;
|
||||
@ -284,7 +284,7 @@ void
|
||||
nsTSubstring_CharT::Assign(const char_type* aData)
|
||||
{
|
||||
if (!Assign(aData, size_type(-1), fallible_t())) {
|
||||
NS_ABORT_OOM(char_traits::length(aData));
|
||||
AllocFailed(char_traits::length(aData));
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,8 +292,8 @@ void
|
||||
nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength)
|
||||
{
|
||||
if (!Assign(aData, aLength, fallible_t())) {
|
||||
NS_ABORT_OOM(aLength == size_type(-1) ? char_traits::length(aData)
|
||||
: aLength);
|
||||
AllocFailed(aLength == size_type(-1) ? char_traits::length(aData)
|
||||
: aLength);
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,7 +326,7 @@ void
|
||||
nsTSubstring_CharT::AssignASCII(const char* aData, size_type aLength)
|
||||
{
|
||||
if (!AssignASCII(aData, aLength, fallible_t())) {
|
||||
NS_ABORT_OOM(aLength);
|
||||
AllocFailed(aLength);
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,7 +363,7 @@ void
|
||||
nsTSubstring_CharT::Assign(const self_type& aStr)
|
||||
{
|
||||
if (!Assign(aStr, fallible_t())) {
|
||||
NS_ABORT_OOM(aStr.Length());
|
||||
AllocFailed(aStr.Length());
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,7 +413,7 @@ void
|
||||
nsTSubstring_CharT::Assign(const substring_tuple_type& aTuple)
|
||||
{
|
||||
if (!Assign(aTuple, fallible_t())) {
|
||||
NS_ABORT_OOM(aTuple.Length());
|
||||
AllocFailed(aTuple.Length());
|
||||
}
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
|
||||
{
|
||||
if (!Replace(aCutStart, aCutLength, aData, aLength,
|
||||
mozilla::fallible_t())) {
|
||||
NS_ABORT_OOM(Length() - aCutLength + 1);
|
||||
AllocFailed(Length() - aCutLength + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -603,7 +603,7 @@ void
|
||||
nsTSubstring_CharT::SetCapacity(size_type aCapacity)
|
||||
{
|
||||
if (!SetCapacity(aCapacity, fallible_t())) {
|
||||
NS_ABORT_OOM(aCapacity);
|
||||
AllocFailed(aCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -784,7 +784,7 @@ nsTSubstring_CharT::StripChar(char_type aChar, int32_t aOffset)
|
||||
}
|
||||
|
||||
if (!EnsureMutable()) { // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
|
||||
// XXX(darin): this code should defer writing until necessary.
|
||||
@ -811,7 +811,7 @@ nsTSubstring_CharT::StripChars(const char_type* aChars, uint32_t aOffset)
|
||||
}
|
||||
|
||||
if (!EnsureMutable()) { // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
|
||||
// XXX(darin): this code should defer writing until necessary.
|
||||
|
@ -146,7 +146,7 @@ public:
|
||||
char_iterator BeginWriting()
|
||||
{
|
||||
if (!EnsureMutable()) {
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
|
||||
return mData;
|
||||
@ -160,7 +160,7 @@ public:
|
||||
char_iterator EndWriting()
|
||||
{
|
||||
if (!EnsureMutable()) {
|
||||
NS_ABORT_OOM(mLength);
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
|
||||
return mData + mLength;
|
||||
@ -742,7 +742,7 @@ public:
|
||||
size_type GetMutableData(char_type** aData, size_type aNewLen = size_type(-1))
|
||||
{
|
||||
if (!EnsureMutable(aNewLen)) {
|
||||
NS_ABORT_OOM(aNewLen == size_type(-1) ? mLength : aNewLen);
|
||||
AllocFailed(aNewLen == size_type(-1) ? mLength : aNewLen);
|
||||
}
|
||||
|
||||
*aData = mData;
|
||||
@ -869,6 +869,20 @@ public:
|
||||
size_t SizeOfIncludingThisEvenIfShared(mozilla::MallocSizeOf aMallocSizeOf)
|
||||
const;
|
||||
|
||||
template<class T>
|
||||
void NS_ABORT_OOM(T)
|
||||
{
|
||||
struct never {};
|
||||
static_assert(mozilla::IsSame<T, never>::value,
|
||||
"In string classes, use AllocFailed to account for sizeof(char_type). "
|
||||
"Use the global ::NS_ABORT_OOM if you really have a count of bytes.");
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE void AllocFailed(size_t aLength)
|
||||
{
|
||||
::NS_ABORT_OOM(aLength * sizeof(char_type));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
friend class nsTObsoleteAStringThunk_CharT;
|
||||
|
Loading…
Reference in New Issue
Block a user