]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Remove incorrect uses of __attribute__((__malloc__)).
authorLasse Collin <lasse.collin@tukaani.org>
Mon, 11 Sep 2023 15:53:31 +0000 (18:53 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 7 May 2024 12:44:54 +0000 (15:44 +0300)
xrealloc() is obviously incorrect, modern GCC docs even
mention realloc() as an example where this attribute
cannot be used.

liblzma's lzma_alloc() and lzma_alloc_zero() would be
correct uses most of the time but custom allocators
may use a memory pool or otherwise hold the pointer
so aliasing issues could happen in theory.

The xstrdup() case likely was correct but I removed it anyway.
Now there are no __malloc__ attributes left in the code.
The allocations aren't in hot paths so this should make
no practical difference.

(cherry picked from commit 359e5c6cb128dab64ea6070d21d1c240f96cea6b)

src/liblzma/common/common.c
src/liblzma/common/common.h
src/xz/util.h

index 8de37d007d4e71ae4002662b9239cabf82215b45..407dd5844dbccebaf20a88115c0de98309312335 100644 (file)
@@ -35,7 +35,7 @@ lzma_version_string(void)
 // Memory allocation //
 ///////////////////////
 
-extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+extern void * lzma_attr_alloc_size(1)
 lzma_alloc(size_t size, const lzma_allocator *allocator)
 {
        // Some malloc() variants return NULL if called with size == 0.
@@ -53,7 +53,7 @@ lzma_alloc(size_t size, const lzma_allocator *allocator)
 }
 
 
-extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+extern void * lzma_attr_alloc_size(1)
 lzma_alloc_zero(size_t size, const lzma_allocator *allocator)
 {
        // Some calloc() variants return NULL if called with size == 0.
index 671d3bc430b875329e2a84f0e1b7a2c348d45742..41754cc8e02f0d568797964ba8155a1017644624 100644 (file)
@@ -280,12 +280,12 @@ struct lzma_internal_s {
 
 /// Allocates memory
 extern void *lzma_alloc(size_t size, const lzma_allocator *allocator)
-               lzma_attribute((__malloc__)) lzma_attr_alloc_size(1);
+               lzma_attr_alloc_size(1);
 
 /// Allocates memory and zeroes it (like calloc()). This can be faster
 /// than lzma_alloc() + memzero() while being backward compatible with
 /// custom allocators.
-extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+extern void * lzma_attr_alloc_size(1)
                lzma_alloc_zero(size_t size, const lzma_allocator *allocator);
 
 /// Frees memory
index a2516bf968038df38ef98915f8b00d075aed15fd..6e824dadb07baf28d0f32e4b2a01b0ba432cdf3f 100644 (file)
 
 /// \brief      Safe realloc() that never returns NULL
 extern void *xrealloc(void *ptr, size_t size)
-               lzma_attribute((__malloc__)) lzma_attr_alloc_size(2);
+               lzma_attr_alloc_size(2);
 
 
 /// \brief      Safe strdup() that never returns NULL
-extern char *xstrdup(const char *src) lzma_attribute((__malloc__));
+extern char *xstrdup(const char *src);
 
 
 /// \brief      Fancy version of strtoull()