Bug 786533 - Replace NS_MIN/NS_MAX in xpcom/ with XPCOM_MIN/XPCOM_MAX to prevent accidental use. r=ehsan

This commit is contained in:
Mats Palmgren 2013-01-15 13:22:03 +01:00
Родитель b7ae90666d
Коммит 5f5d30eb5b
26 изменённых файлов: 51 добавлений и 51 удалений

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

@ -145,7 +145,7 @@ FileLocation::Data::Copy(char *buf, uint32_t len)
{
if (mFd) {
for (uint32_t totalRead = 0; totalRead < len; ) {
int32_t read = PR_Read(mFd, buf + totalRead, NS_MIN(len - totalRead, uint32_t(INT32_MAX)));
int32_t read = PR_Read(mFd, buf + totalRead, XPCOM_MIN(len - totalRead, uint32_t(INT32_MAX)));
if (read < 0)
return NS_ErrorAccordingToNSPR();
totalRead += read;

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

@ -63,7 +63,7 @@ public:
size_t EnsureCapacity(size_t capacity) {
if (capacity > mCapacity) {
// make sure we at least double in size
mCapacity = NS_MAX(capacity, mCapacity*2);
mCapacity = XPCOM_MAX(capacity, mCapacity*2);
mBuffer = static_cast<char*>(realloc(mBuffer, mCapacity));
mCapacity = moz_malloc_usable_size(mBuffer);
}

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

@ -181,7 +181,7 @@ template <class T, uint32_t K> class nsExpirationTracker {
for (;;) {
// Objects could have been removed so index could be outside
// the array
index = NS_MIN(index, generation.Length());
index = XPCOM_MIN(index, generation.Length());
if (index == 0)
break;
--index;

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

@ -164,9 +164,9 @@ loop: SWAPINIT(a, es);
}
pn = (char *)a + n * es;
r = NS_MIN(pa - (char *)a, pb - pa);
r = XPCOM_MIN(pa - (char *)a, pb - pa);
vecswap(a, pb - r, r);
r = NS_MIN<size_t>(pd - pc, pn - pd - es);
r = XPCOM_MIN<size_t>(pd - pc, pn - pd - es);
vecswap(pb, pn - r, r);
if ((r = pb - pa) > (int)es)
NS_QuickSort(a, r / es, es, cmp, data);

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

@ -353,8 +353,8 @@ nsTArray_base<Alloc>::SwapArrayElements(nsTArray_base<Allocator>& other,
other.UsesAutoArrayBuffer(),
"One of the arrays should be using its auto buffer.");
size_type smallerLength = NS_MIN(Length(), other.Length());
size_type largerLength = NS_MAX(Length(), other.Length());
size_type smallerLength = XPCOM_MIN(Length(), other.Length());
size_type largerLength = XPCOM_MAX(Length(), other.Length());
void *smallerElements, *largerElements;
if (Length() <= other.Length()) {
smallerElements = Hdr() + 1;

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

@ -258,7 +258,7 @@ CompareVP(VersionPartW &v1, VersionPartW &v2)
if (r)
return r;
r = wcsncmp(v1.strB, v2.strB, NS_MIN(v1.strBlen,v2.strBlen));
r = wcsncmp(v1.strB, v2.strB, XPCOM_MIN(v1.strBlen,v2.strBlen));
if (r)
return r;

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

@ -233,7 +233,7 @@ bool nsVoidArray::GrowArrayBy(int32_t aGrowBy)
// Also, limit the increase in size to about a VM page or two.
if (GetArraySize() >= kMaxGrowArrayBy)
{
newCapacity = GetArraySize() + NS_MAX(kMaxGrowArrayBy,aGrowBy);
newCapacity = GetArraySize() + XPCOM_MAX(kMaxGrowArrayBy,aGrowBy);
newSize = SIZEOF_IMPL(newCapacity);
}
else

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

@ -273,7 +273,7 @@ PL_DHashTableSetAlphaBounds(PLDHashTable *table,
"PL_DHASH_MIN_SIZE - (maxAlpha * PL_DHASH_MIN_SIZE) >= 1");
if (PL_DHASH_MIN_SIZE - (maxAlpha * PL_DHASH_MIN_SIZE) < 1) {
maxAlpha = (float)
(PL_DHASH_MIN_SIZE - NS_MAX(PL_DHASH_MIN_SIZE / 256, 1))
(PL_DHASH_MIN_SIZE - XPCOM_MAX(PL_DHASH_MIN_SIZE / 256, 1))
/ PL_DHASH_MIN_SIZE;
}
@ -286,7 +286,7 @@ PL_DHashTableSetAlphaBounds(PLDHashTable *table,
"minAlpha < maxAlpha / 2");
if (minAlpha >= maxAlpha / 2) {
size = PL_DHASH_TABLE_SIZE(table);
minAlpha = (size * maxAlpha - NS_MAX(size / 256, 1u)) / (2 * size);
minAlpha = (size * maxAlpha - XPCOM_MAX(size / 256, 1u)) / (2 * size);
}
table->maxAlphaFrac = (uint8_t)(maxAlpha * 256);

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

@ -403,7 +403,7 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset)
rv = mStreams[i]->Available(&avail);
NS_ENSURE_SUCCESS(rv, rv);
int64_t newPos = NS_MIN(remaining, streamPos + (int64_t)avail);
int64_t newPos = XPCOM_MIN(remaining, streamPos + (int64_t)avail);
rv = stream->Seek(NS_SEEK_SET, newPos);
NS_ENSURE_SUCCESS(rv, rv);
@ -434,7 +434,7 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset)
rv = mStreams[i]->Available(&avail);
NS_ENSURE_SUCCESS(rv, rv);
int64_t seek = NS_MIN((int64_t)avail, remaining);
int64_t seek = XPCOM_MIN((int64_t)avail, remaining);
rv = stream->Seek(NS_SEEK_CUR, seek);
NS_ENSURE_SUCCESS(rv, rv);
@ -458,7 +458,7 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset)
rv = stream->Tell(&pos);
NS_ENSURE_SUCCESS(rv, rv);
int64_t seek = NS_MIN(pos, remaining);
int64_t seek = XPCOM_MIN(pos, remaining);
rv = stream->Seek(NS_SEEK_CUR, -seek);
NS_ENSURE_SUCCESS(rv, rv);
@ -529,7 +529,7 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset)
rv = stream->Tell(&avail);
NS_ENSURE_SUCCESS(rv, rv);
int64_t newPos = streamPos + NS_MIN(avail, std::abs(remaining));
int64_t newPos = streamPos + XPCOM_MIN(avail, std::abs(remaining));
rv = stream->Seek(NS_SEEK_END, -newPos);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -935,7 +935,7 @@ nsPipeInputStream::Search(const char *forString,
len2 = limit2 - cursor2;
// check if the string is straddling the next buffer segment
uint32_t lim = NS_MIN(strLen, len2 + 1);
uint32_t lim = XPCOM_MIN(strLen, len2 + 1);
for (i = 0; i < lim; ++i) {
uint32_t strPart1Len = strLen - i - 1;
uint32_t strPart2Len = strLen - strPart1Len;

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

@ -41,7 +41,7 @@ nsScriptableInputStream::Read(uint32_t aCount, char **_retval) {
if (NS_FAILED(rv)) return rv;
// bug716556 - Ensure count+1 doesn't overflow
uint32_t count = NS_MIN((uint32_t)NS_MIN<uint64_t>(count64, aCount), UINT32_MAX - 1);
uint32_t count = XPCOM_MIN((uint32_t)XPCOM_MIN<uint64_t>(count64, aCount), UINT32_MAX - 1);
buffer = (char*)nsMemory::Alloc(count+1); // make room for '\0'
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;

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

@ -180,7 +180,7 @@ nsStorageStream::Write(const char *aBuffer, uint32_t aCount, uint32_t *aNumWritt
this, mWriteCursor, mSegmentEnd));
}
count = NS_MIN(availableInSegment, remaining);
count = XPCOM_MIN(availableInSegment, remaining);
memcpy(mWriteCursor, readCursor, count);
remaining -= count;
readCursor += count;
@ -418,12 +418,12 @@ nsStorageInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, uin
mSegmentNum++;
mReadCursor = 0;
mSegmentEnd = NS_MIN(mSegmentSize, available);
mSegmentEnd = XPCOM_MIN(mSegmentSize, available);
availableInSegment = mSegmentEnd;
}
const char *cur = mStorageStream->mSegmentedBuffer->GetSegment(mSegmentNum);
count = NS_MIN(availableInSegment, remainingCapacity);
count = XPCOM_MIN(availableInSegment, remainingCapacity);
rv = writer(this, closure, cur + mReadCursor, aCount - remainingCapacity,
count, &bytesConsumed);
if (NS_FAILED(rv) || (bytesConsumed == 0))
@ -513,7 +513,7 @@ nsStorageInputStream::Seek(uint32_t aPosition)
mSegmentNum = SegNum(aPosition);
mReadCursor = SegOffset(aPosition);
uint32_t available = length - aPosition;
mSegmentEnd = mReadCursor + NS_MIN(mSegmentSize - mReadCursor, available);
mSegmentEnd = mReadCursor + XPCOM_MIN(mSegmentSize - mReadCursor, available);
mLogicalCursor = aPosition;
return NS_OK;
}

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

@ -629,7 +629,7 @@ NS_ConsumeStream(nsIInputStream *stream, uint32_t maxCount, nsACString &result)
if (avail64 == 0)
break;
uint32_t avail = (uint32_t)NS_MIN<uint64_t>(avail64, maxCount);
uint32_t avail = (uint32_t)XPCOM_MIN<uint64_t>(avail64, maxCount);
// resize result buffer
uint32_t length = result.Length();

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

@ -69,7 +69,7 @@ StringUnicharInputStream::ReadSegments(nsWriteUnicharSegmentFun aWriter,
uint32_t totalBytesWritten = 0;
nsresult rv;
aCount = NS_MIN(mString.Length() - mPos, aCount);
aCount = XPCOM_MIN(mString.Length() - mPos, aCount);
nsAString::const_iterator iter;
mString.BeginReading(iter);

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

@ -28,7 +28,7 @@ NS_ROUNDUP( const T& a, const T& b )
template <class T>
inline
const T&
NS_MIN( const T& a, const T& b )
XPCOM_MIN( const T& a, const T& b )
{
return b < a ? b : a;
}
@ -37,7 +37,7 @@ NS_MIN( const T& a, const T& b )
template <class T>
inline
const T&
NS_MAX( const T& a, const T& b )
XPCOM_MAX( const T& a, const T& b )
{
return a > b ? a : b;
}
@ -61,7 +61,7 @@ const T&
clamped( const T& a, const T& min, const T& max )
{
NS_ABORT_IF_FALSE(max >= min, "clamped(): max must be greater than or equal to min");
return NS_MIN(NS_MAX(a, min), max);
return XPCOM_MIN(XPCOM_MAX(a, min), max);
}
}

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

@ -188,12 +188,12 @@ typedef nsAutoString nsVoidableString;
inline int32_t MinInt(int32_t x, int32_t y)
{
return NS_MIN(x, y);
return XPCOM_MIN(x, y);
}
inline int32_t MaxInt(int32_t x, int32_t y)
{
return NS_MAX(x, y);
return XPCOM_MAX(x, y);
}
/**

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

@ -134,7 +134,7 @@ class nsReadingIterator
{
if (n > 0)
{
difference_type step = NS_MIN(n, size_forward());
difference_type step = XPCOM_MIN(n, size_forward());
NS_ASSERTION(step>0, "can't advance a reading iterator beyond the end of a string");
@ -142,7 +142,7 @@ class nsReadingIterator
}
else if (n < 0)
{
difference_type step = NS_MAX(n, -size_backward());
difference_type step = XPCOM_MAX(n, -size_backward());
NS_ASSERTION(step<0, "can't advance (backward) a reading iterator beyond the end of a string");
@ -268,7 +268,7 @@ class nsWritingIterator
{
if (n > 0)
{
difference_type step = NS_MIN(n, size_forward());
difference_type step = XPCOM_MIN(n, size_forward());
NS_ASSERTION(step>0, "can't advance a writing iterator beyond the end of a string");
@ -276,7 +276,7 @@ class nsWritingIterator
}
else if (n < 0)
{
difference_type step = NS_MAX(n, -size_backward());
difference_type step = XPCOM_MAX(n, -size_backward());
NS_ASSERTION(step<0, "can't advance (backward) a writing iterator beyond the end of a string");

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

@ -286,7 +286,7 @@ class nsTString_CharT : public nsTSubstring_CharT
size_type Right( self_type& aResult, size_type aCount ) const
{
aCount = NS_MIN(mLength, aCount);
aCount = XPCOM_MIN(mLength, aCount);
return Mid(aResult, mLength - aCount, aCount);
}

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

@ -710,7 +710,7 @@ class nsTSubstring_CharT
bool ReplacePrep(index_type cutStart, size_type cutLength,
size_type newLength) NS_WARN_UNUSED_RESULT
{
cutLength = NS_MIN(cutLength, mLength - cutStart);
cutLength = XPCOM_MIN(cutLength, mLength - cutStart);
uint32_t newTotalLen = mLength - cutLength + newLength;
if (cutStart == mLength && Capacity() > newTotalLen) {
mFlags &= ~F_VOIDED;

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

@ -578,7 +578,7 @@ class CopyToUpperCase
uint32_t
write( const char* aSource, uint32_t aSourceLength )
{
uint32_t len = NS_MIN(uint32_t(mIter.size_forward()), aSourceLength);
uint32_t len = XPCOM_MIN(uint32_t(mIter.size_forward()), aSourceLength);
char* cp = mIter.get();
const char* end = aSource + len;
while (aSource != end) {
@ -657,7 +657,7 @@ class CopyToLowerCase
uint32_t
write( const char* aSource, uint32_t aSourceLength )
{
uint32_t len = NS_MIN(uint32_t(mIter.size_forward()), aSourceLength);
uint32_t len = XPCOM_MIN(uint32_t(mIter.size_forward()), aSourceLength);
char* cp = mIter.get();
const char* end = aSource + len;
while (aSource != end) {

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

@ -925,7 +925,7 @@ nsCString::Compare( const char* aString, bool aIgnoreCase, int32_t aCount ) cons
{
uint32_t strLen = char_traits::length(aString);
int32_t maxCount = int32_t(NS_MIN(mLength, strLen));
int32_t maxCount = int32_t(XPCOM_MIN(mLength, strLen));
int32_t compareCount;
if (aCount < 0 || aCount > maxCount)
@ -954,7 +954,7 @@ nsString::EqualsIgnoreCase( const char* aString, int32_t aCount ) const
{
uint32_t strLen = nsCharTraits<char>::length(aString);
int32_t maxCount = int32_t(NS_MIN(mLength, strLen));
int32_t maxCount = int32_t(XPCOM_MIN(mLength, strLen));
int32_t compareCount;
if (aCount < 0 || aCount > maxCount)

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

@ -16,7 +16,7 @@ nsTDependentSubstring_CharT::Rebind( const substring_type& str, uint32_t startPo
startPos = strLength;
mData = const_cast<char_type*>(str.Data()) + startPos;
mLength = NS_MIN(length, strLength - startPos);
mLength = XPCOM_MIN(length, strLength - startPos);
SetDataFlags(F_NONE);
}

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

@ -18,7 +18,7 @@ Compare( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_Cha
size_type lLength = leftIter.size_forward();
size_type rLength = rightIter.size_forward();
size_type lengthToCompare = NS_MIN(lLength, rLength);
size_type lengthToCompare = XPCOM_MIN(lLength, rLength);
int result;
if ( (result = comp(leftIter.get(), rightIter.get(), lengthToCompare, lengthToCompare)) == 0 )

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

@ -75,9 +75,9 @@ nsTSubstring_CharT::MutatePrep( size_type capacity, char_type** oldData, uint32_
size_type temp = curCapacity;
while (temp < capacity)
temp <<= 1;
NS_ASSERTION(NS_MIN(temp, kMaxCapacity) >= capacity,
NS_ASSERTION(XPCOM_MIN(temp, kMaxCapacity) >= capacity,
"should have hit the early return at the top");
capacity = NS_MIN(temp, kMaxCapacity);
capacity = XPCOM_MIN(temp, kMaxCapacity);
}
//
@ -451,7 +451,7 @@ nsTSubstring_CharT::Adopt( char_type* data, size_type length )
void
nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, char_type c )
{
cutStart = NS_MIN(cutStart, Length());
cutStart = XPCOM_MIN(cutStart, Length());
if (ReplacePrep(cutStart, cutLength, 1))
mData[cutStart] = c;
@ -479,7 +479,7 @@ nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, const cha
}
}
cutStart = NS_MIN(cutStart, Length());
cutStart = XPCOM_MIN(cutStart, Length());
if (ReplacePrep(cutStart, cutLength, length) && length > 0)
char_traits::copy(mData + cutStart, data, length);
@ -502,7 +502,7 @@ nsTSubstring_CharT::ReplaceASCII( index_type cutStart, size_type cutLength, cons
}
#endif
cutStart = NS_MIN(cutStart, Length());
cutStart = XPCOM_MIN(cutStart, Length());
if (ReplacePrep(cutStart, cutLength, length) && length > 0)
char_traits::copyASCII(mData + cutStart, data, length);
@ -520,7 +520,7 @@ nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, const sub
size_type length = tuple.Length();
cutStart = NS_MIN(cutStart, Length());
cutStart = XPCOM_MIN(cutStart, Length());
if (ReplacePrep(cutStart, cutLength, length) && length > 0)
tuple.WriteTo(mData + cutStart, length);
@ -554,7 +554,7 @@ nsTSubstring_CharT::SetCapacity( size_type capacity, const fallible_t& )
return false; // out-of-memory
// compute new string length
size_type newLen = NS_MIN(mLength, capacity);
size_type newLen = XPCOM_MIN(mLength, capacity);
if (oldData)
{

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

@ -16,7 +16,7 @@ LossyConvertEncoding16to8::write_sse2(const PRUnichar* aSource,
// Align source to a 16-byte boundary.
uint32_t i = 0;
uint32_t alignLen =
NS_MIN<uint32_t>(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf) / sizeof(PRUnichar));
XPCOM_MIN<uint32_t>(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf) / sizeof(PRUnichar));
for (; i < alignLen; i++) {
dest[i] = static_cast<unsigned char>(aSource[i]);
}
@ -69,7 +69,7 @@ LossyConvertEncoding8to16::write_sse2(const char* aSource,
// to wait for a load to complete, but you can keep on moving after issuing a
// store.
uint32_t i = 0;
uint32_t alignLen = NS_MIN(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf));
uint32_t alignLen = XPCOM_MIN(aSourceLength, uint32_t(-NS_PTR_TO_INT32(aSource) & 0xf));
for (; i < alignLen; i++) {
dest[i] = static_cast<unsigned char>(aSource[i]);
}

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

@ -282,7 +282,7 @@ TestShortWrites(nsIInputStream* in, nsIOutputStream* out)
char* buf = PR_smprintf("%d %s", i, kTestPattern);
uint32_t len = strlen(buf);
len = len * rand() / RAND_MAX;
len = NS_MAX(1, len);
len = XPCOM_MAX(1, len);
rv = WriteAll(out, buf, len, &writeCount);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(writeCount == len, "didn't write enough");
@ -391,7 +391,7 @@ TestChainedPipes()
char* buf = PR_smprintf("%d %s", i, kTestPattern);
uint32_t len = strlen(buf);
len = len * rand() / RAND_MAX;
len = NS_MAX(1, len);
len = XPCOM_MAX(1, len);
rv = WriteAll(out1, buf, len, &writeCount);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(writeCount == len, "didn't write enough");