зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1486690 - Rename nsMemory::Clone() and remove unnecessary checks after it. r=glandium
The 'x' in the new name makes it clearer that it's infallible. --HG-- extra : rebase_source : 51fd946c482befe8a8ca5bd88ecc967971f455da
This commit is contained in:
Родитель
2fcd08a173
Коммит
fe34f19459
|
@ -516,7 +516,7 @@ nsAuthGSSAPI::GetNextToken(const void *inToken,
|
|||
|
||||
*outTokenLen = output_token.length;
|
||||
if (output_token.length != 0)
|
||||
*outToken = nsMemory::Clone(output_token.value, output_token.length);
|
||||
*outToken = moz_xmemdup(output_token.value, output_token.length);
|
||||
else
|
||||
*outToken = nullptr;
|
||||
|
||||
|
@ -565,7 +565,7 @@ nsAuthGSSAPI::Unwrap(const void *inToken,
|
|||
*outTokenLen = output_token.length;
|
||||
|
||||
if (output_token.length)
|
||||
*outToken = nsMemory::Clone(output_token.value, output_token.length);
|
||||
*outToken = moz_xmemdup(output_token.value, output_token.length);
|
||||
else
|
||||
*outToken = nullptr;
|
||||
|
||||
|
@ -607,7 +607,7 @@ nsAuthGSSAPI::Wrap(const void *inToken,
|
|||
*outTokenLen = output_token.length;
|
||||
|
||||
/* it is not possible for output_token.length to be zero */
|
||||
*outToken = nsMemory::Clone(output_token.value, output_token.length);
|
||||
*outToken = moz_xmemdup(output_token.value, output_token.length);
|
||||
gss_release_buffer_ptr(&minor_status, &output_token);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -542,10 +542,8 @@ nsAuthSSPI::Unwrap(const void *inToken,
|
|||
*outToken = ib[1].pvBuffer;
|
||||
}
|
||||
else {
|
||||
*outToken = nsMemory::Clone(ib[1].pvBuffer, ib[1].cbBuffer);
|
||||
*outToken = moz_xmemdup(ib[1].pvBuffer, ib[1].cbBuffer);
|
||||
free(ib[0].pvBuffer);
|
||||
if (!*outToken)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
*outTokenLen = ib[1].cbBuffer;
|
||||
}
|
||||
|
|
|
@ -235,9 +235,7 @@ nsAuthSambaNTLM::GetNextToken(const void *inToken,
|
|||
{
|
||||
if (!inToken) {
|
||||
/* someone wants our initial message */
|
||||
*outToken = nsMemory::Clone(mInitialMessage, mInitialMessageLen);
|
||||
if (!*outToken)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
*outToken = moz_xmemdup(mInitialMessage, mInitialMessageLen);
|
||||
*outTokenLen = mInitialMessageLen;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -266,11 +264,8 @@ nsAuthSambaNTLM::GetNextToken(const void *inToken,
|
|||
uint8_t* buf = ExtractMessage(line, outTokenLen);
|
||||
if (!buf)
|
||||
return NS_ERROR_FAILURE;
|
||||
*outToken = nsMemory::Clone(buf, *outTokenLen);
|
||||
*outToken = moz_xmemdup(buf, *outTokenLen);
|
||||
PR_Free(buf);
|
||||
if (!*outToken) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// We're done. Close our file descriptors now and reap the helper
|
||||
// process.
|
||||
|
|
|
@ -306,8 +306,8 @@ NS_IMETHODIMP nsJSIID::GetNumber(char * *aNumber)
|
|||
const nsIID* id;
|
||||
mInfo->GetIIDShared(&id);
|
||||
id->ToProvidedString(str);
|
||||
*aNumber = (char*) nsMemory::Clone(str, NSID_LENGTH);
|
||||
return *aNumber ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
*aNumber = (char*) moz_xmemdup(str, NSID_LENGTH);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const nsID*) nsJSIID::GetID()
|
||||
|
|
|
@ -122,6 +122,14 @@ moz_xstrndup(const char* str, size_t strsize)
|
|||
}
|
||||
#endif // if defined(HAVE_STRNDUP)
|
||||
|
||||
void*
|
||||
moz_xmemdup(const void* ptr, size_t size)
|
||||
{
|
||||
void* newPtr = moz_xmalloc(size);
|
||||
memcpy(newPtr, ptr, size);
|
||||
return newPtr;
|
||||
}
|
||||
|
||||
#ifndef HAVE_MEMALIGN
|
||||
// We always have a definition of memalign, but system headers don't
|
||||
// necessarily come with a declaration.
|
||||
|
|
|
@ -72,6 +72,17 @@ MFBT_API void* moz_xrealloc(void* ptr, size_t size)
|
|||
MFBT_API char* moz_xstrdup(const char* str)
|
||||
MOZ_ALLOCATOR;
|
||||
|
||||
#if defined(HAVE_STRNDUP)
|
||||
MFBT_API char* moz_xstrndup(const char* str, size_t strsize)
|
||||
MOZ_ALLOCATOR;
|
||||
#endif /* if defined(HAVE_STRNDUP) */
|
||||
|
||||
MFBT_API void* moz_xmemdup(const void* ptr, size_t size)
|
||||
MOZ_ALLOCATOR;
|
||||
|
||||
MFBT_API void* moz_xmemalign(size_t boundary, size_t size)
|
||||
MOZ_ALLOCATOR;
|
||||
|
||||
MFBT_API size_t moz_malloc_usable_size(void *ptr);
|
||||
|
||||
MFBT_API size_t moz_malloc_size_of(const void *ptr);
|
||||
|
@ -82,14 +93,6 @@ MFBT_API size_t moz_malloc_size_of(const void *ptr);
|
|||
*/
|
||||
MFBT_API size_t moz_malloc_enclosing_size_of(const void *ptr);
|
||||
|
||||
#if defined(HAVE_STRNDUP)
|
||||
MFBT_API char* moz_xstrndup(const char* str, size_t strsize)
|
||||
MOZ_ALLOCATOR;
|
||||
#endif /* if defined(HAVE_STRNDUP) */
|
||||
|
||||
MFBT_API void* moz_xmemalign(size_t boundary, size_t size)
|
||||
MOZ_ALLOCATOR;
|
||||
|
||||
MOZ_END_EXTERN_C
|
||||
|
||||
|
||||
|
|
|
@ -2943,14 +2943,8 @@ nsPrefBranch::GetChildList(const char* aStartingAt,
|
|||
// back to us because if they do we are going to add mPrefRoot again.
|
||||
const nsCString& element = prefArray[dwIndex];
|
||||
outArray[dwIndex] =
|
||||
(char*)nsMemory::Clone(element.get() + mPrefRoot.Length(),
|
||||
element.Length() - mPrefRoot.Length() + 1);
|
||||
|
||||
if (!outArray[dwIndex]) {
|
||||
// We ran out of memory... this is annoying.
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(dwIndex, outArray);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
(char*) moz_xmemdup(element.get() + mPrefRoot.Length(),
|
||||
element.Length() - mPrefRoot.Length() + 1);
|
||||
}
|
||||
*aChildArray = outArray;
|
||||
}
|
||||
|
|
|
@ -407,8 +407,7 @@ nsMIMEHeaderParamImpl::DoParameterInternal(const char *aHeaderValue,
|
|||
if (str == start)
|
||||
return NS_ERROR_FIRST_HEADER_FIELD_COMPONENT_EMPTY;
|
||||
|
||||
*aResult = (char *) nsMemory::Clone(start, (str - start) + 1);
|
||||
NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
|
||||
*aResult = (char*) moz_xmemdup(start, (str - start) + 1);
|
||||
(*aResult)[str - start] = '\0'; // null-terminate
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -630,10 +629,8 @@ nsMIMEHeaderParamImpl::DoParameterInternal(const char *aHeaderValue,
|
|||
}
|
||||
|
||||
// allocate buffer for the raw value
|
||||
char *tmpResult = (char *) nsMemory::Clone(rawValStart, rawValLength + 1);
|
||||
if (!tmpResult) {
|
||||
goto increment_str;
|
||||
}
|
||||
char* tmpResult =
|
||||
(char*) moz_xmemdup(rawValStart, rawValLength + 1);
|
||||
*(tmpResult + rawValLength) = 0;
|
||||
|
||||
nsUnescape(tmpResult);
|
||||
|
@ -724,17 +721,13 @@ increment_str:
|
|||
// then return charset and lang as well
|
||||
if (aLang && !lang.IsEmpty()) {
|
||||
uint32_t len = lang.Length();
|
||||
*aLang = (char *) nsMemory::Clone(lang.BeginReading(), len + 1);
|
||||
if (*aLang) {
|
||||
*(*aLang + len) = 0;
|
||||
}
|
||||
*aLang = (char*) moz_xmemdup(lang.BeginReading(), len + 1);
|
||||
*(*aLang + len) = 0;
|
||||
}
|
||||
if (aCharset && !charset.IsEmpty()) {
|
||||
uint32_t len = charset.Length();
|
||||
*aCharset = (char *) nsMemory::Clone(charset.BeginReading(), len + 1);
|
||||
if (*aCharset) {
|
||||
*(*aCharset + len) = 0;
|
||||
}
|
||||
*aCharset = (char*) moz_xmemdup(charset.BeginReading(), len + 1);
|
||||
*(*aCharset + len) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -303,8 +303,7 @@ struct variant_blob_traits<uint8_t[], false>
|
|||
}
|
||||
|
||||
// Otherwise, we copy the array.
|
||||
*_result = nsMemory::Clone(aData.Elements(), aData.Length() * sizeof(uint8_t));
|
||||
NS_ENSURE_TRUE(*_result, NS_ERROR_OUT_OF_MEMORY);
|
||||
*_result = moz_xmemdup(aData.Elements(), aData.Length() * sizeof(uint8_t));
|
||||
|
||||
// Set type and size
|
||||
*_type = nsIDataType::VTYPE_UINT8;
|
||||
|
|
|
@ -142,9 +142,7 @@ ArgValueArray::GetBlob(uint32_t aIndex,
|
|||
ENSURE_INDEX_VALUE(aIndex, mArgc);
|
||||
|
||||
int size = ::sqlite3_value_bytes(mArgv[aIndex]);
|
||||
void *blob = nsMemory::Clone(::sqlite3_value_blob(mArgv[aIndex]), size);
|
||||
NS_ENSURE_TRUE(blob, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
void* blob = moz_xmemdup(::sqlite3_value_blob(mArgv[aIndex]), size);
|
||||
*_blob = static_cast<uint8_t *>(blob);
|
||||
*_size = size;
|
||||
return NS_OK;
|
||||
|
|
|
@ -783,8 +783,7 @@ Statement::GetBlob(uint32_t aIndex,
|
|||
int size = ::sqlite3_column_bytes(mDBStatement, aIndex);
|
||||
void *blob = nullptr;
|
||||
if (size) {
|
||||
blob = nsMemory::Clone(::sqlite3_column_blob(mDBStatement, aIndex), size);
|
||||
NS_ENSURE_TRUE(blob, NS_ERROR_OUT_OF_MEMORY);
|
||||
blob = moz_xmemdup(::sqlite3_column_blob(mDBStatement, aIndex), size);
|
||||
}
|
||||
|
||||
*_blob = static_cast<uint8_t *>(blob);
|
||||
|
|
|
@ -1105,15 +1105,9 @@ NS_IMETHODIMP GfxInfoBase::GetFailures(uint32_t* failureCount,
|
|||
LoggingRecord::const_iterator it;
|
||||
uint32_t i=0;
|
||||
for(it = loggedStrings.begin() ; it != loggedStrings.end(); ++it, i++) {
|
||||
(*failures)[i] = (char*)nsMemory::Clone(Get<1>(*it).c_str(), Get<1>(*it).size() + 1);
|
||||
(*failures)[i] =
|
||||
(char*) moz_xmemdup(Get<1>(*it).c_str(), Get<1>(*it).size() + 1);
|
||||
if (indices) (*indices)[i] = Get<0>(*it);
|
||||
|
||||
if (!(*failures)[i]) {
|
||||
/* <sarcasm> I'm too afraid to use an inline function... </sarcasm> */
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, (*failures));
|
||||
*failureCount = i;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,14 +27,6 @@ nsMemory::HeapMinimize(bool aImmediate)
|
|||
return mem->HeapMinimize(aImmediate);
|
||||
}
|
||||
|
||||
void*
|
||||
nsMemory::Clone(const void* aPtr, size_t aSize)
|
||||
{
|
||||
void* newPtr = moz_xmalloc(aSize);
|
||||
memcpy(newPtr, aPtr, aSize);
|
||||
return newPtr;
|
||||
}
|
||||
|
||||
nsIMemory*
|
||||
nsMemory::GetGlobalMemoryService()
|
||||
{
|
||||
|
|
|
@ -34,7 +34,6 @@ class nsMemory
|
|||
{
|
||||
public:
|
||||
static nsresult HeapMinimize(bool aImmediate);
|
||||
static void* Clone(const void* aPtr, size_t aSize);
|
||||
static nsIMemory* GetGlobalMemoryService(); // AddRefs
|
||||
};
|
||||
|
||||
|
|
|
@ -1493,10 +1493,7 @@ nsDiscriminatedUnion::SetFromStringWithSize(uint32_t aSize,
|
|||
if (!aValue) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (!(u.str.mStringValue =
|
||||
(char*)nsMemory::Clone(aValue, (aSize + 1) * sizeof(char)))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
u.str.mStringValue = (char*) moz_xmemdup(aValue, (aSize + 1) * sizeof(char));
|
||||
u.str.mStringLength = aSize;
|
||||
DATA_SETTER_EPILOGUE(VTYPE_STRING_SIZE_IS);
|
||||
return NS_OK;
|
||||
|
@ -1509,10 +1506,8 @@ nsDiscriminatedUnion::SetFromWStringWithSize(uint32_t aSize,
|
|||
if (!aValue) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (!(u.wstr.mWStringValue =
|
||||
(char16_t*)nsMemory::Clone(aValue, (aSize + 1) * sizeof(char16_t)))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
u.wstr.mWStringValue =
|
||||
(char16_t*) moz_xmemdup(aValue, (aSize + 1) * sizeof(char16_t));
|
||||
u.wstr.mWStringLength = aSize;
|
||||
DATA_SETTER_EPILOGUE(VTYPE_WSTRING_SIZE_IS);
|
||||
return NS_OK;
|
||||
|
|
Загрузка…
Ссылка в новой задаче