diff --git a/memory/mozalloc/cxxalloc.cpp b/memory/mozalloc/cxxalloc.cpp index 07ebef7f35af..41f419fe2dd6 100644 --- a/memory/mozalloc/cxxalloc.cpp +++ b/memory/mozalloc/cxxalloc.cpp @@ -15,7 +15,7 @@ #include "mozilla/Attributes.h" -extern "C" MFBT_API void* moz_xmalloc(size_t size) MOZ_ALLOCATOR; +extern "C" MFBT_API void* moz_xmalloc(size_t size) MOZ_INFALLIBLE_ALLOCATOR; namespace std { struct nothrow_t; diff --git a/memory/mozalloc/mozalloc.h b/memory/mozalloc/mozalloc.h index a80afbd5b0eb..74af281d294e 100644 --- a/memory/mozalloc/mozalloc.h +++ b/memory/mozalloc/mozalloc.h @@ -75,21 +75,24 @@ MOZ_BEGIN_EXTERN_C * passing that pointer to |free()|. */ -MFBT_API void* moz_xmalloc(size_t size) MOZ_ALLOCATOR; +MFBT_API void* moz_xmalloc(size_t size) MOZ_INFALLIBLE_ALLOCATOR; -MFBT_API void* moz_xcalloc(size_t nmemb, size_t size) MOZ_ALLOCATOR; +MFBT_API void* moz_xcalloc(size_t nmemb, size_t size) MOZ_INFALLIBLE_ALLOCATOR; -MFBT_API void* moz_xrealloc(void* ptr, size_t size) MOZ_ALLOCATOR; +MFBT_API void* moz_xrealloc(void* ptr, size_t size) MOZ_INFALLIBLE_ALLOCATOR; -MFBT_API char* moz_xstrdup(const char* str) MOZ_ALLOCATOR; +MFBT_API char* moz_xstrdup(const char* str) MOZ_INFALLIBLE_ALLOCATOR; #if defined(HAVE_STRNDUP) -MFBT_API char* moz_xstrndup(const char* str, size_t strsize) MOZ_ALLOCATOR; +MFBT_API char* moz_xstrndup(const char* str, + size_t strsize) MOZ_INFALLIBLE_ALLOCATOR; #endif /* if defined(HAVE_STRNDUP) */ -MFBT_API void* moz_xmemdup(const void* ptr, size_t size) MOZ_ALLOCATOR; +MFBT_API void* moz_xmemdup(const void* ptr, + size_t size) MOZ_INFALLIBLE_ALLOCATOR; -MFBT_API void* moz_xmemalign(size_t boundary, size_t size) MOZ_ALLOCATOR; +MFBT_API void* moz_xmemalign(size_t boundary, + size_t size) MOZ_INFALLIBLE_ALLOCATOR; MFBT_API size_t moz_malloc_usable_size(void* ptr); diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index 62cde0a1768b..84341f59f2f9 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -353,8 +353,11 @@ */ #if defined(__GNUC__) || defined(__clang__) # define MOZ_ALLOCATOR __attribute__((malloc, warn_unused_result)) +# define MOZ_INFALLIBLE_ALLOCATOR \ + __attribute__((malloc, warn_unused_result, returns_nonnull)) #else # define MOZ_ALLOCATOR +# define MOZ_INFALLIBLE_ALLOCATOR #endif /**