Message ID | 20181124210202.52207-1-mark.hsj@gmail.com |
---|---|
State | Accepted |
Commit | 4361293fcf59edb56879c36edcd25f0a91e0edf8 |
Headers | show |
On Sat, Nov 24, 2018 at 01:02:02PM -0800, Mark Harris wrote: > The alloc_size attribute is valid only on functions that return a > pointer. GCC 9 (not yet released) warns about invalid usage: > > ./libavutil/mem.h:342:1: warning: 'alloc_size' attribute ignored on a function returning int' [-Wattributes] > 342 | av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); > | ^~~~~~~~~~~~~ Is the attribute also useless on all other compilers ? thx [...]
On 11/25/2018 10:01 PM, Michael Niedermayer wrote: > On Sat, Nov 24, 2018 at 01:02:02PM -0800, Mark Harris wrote: >> The alloc_size attribute is valid only on functions that return a >> pointer. GCC 9 (not yet released) warns about invalid usage: >> >> ./libavutil/mem.h:342:1: warning: 'alloc_size' attribute ignored on a function returning int' [-Wattributes] >> 342 | av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); >> | ^~~~~~~~~~~~~ > > Is the attribute also useless on all other compilers ? The attribute is only used when __GNUC__ is defined, so it should for any such compiler (GCC and Clang). https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > > thx > > [...] > > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >
On 2018-11-25 17:29, James Almer wrote: > On 11/25/2018 10:01 PM, Michael Niedermayer wrote: >> On Sat, Nov 24, 2018 at 01:02:02PM -0800, Mark Harris wrote: >>> The alloc_size attribute is valid only on functions that return a >>> pointer. GCC 9 (not yet released) warns about invalid usage: >>> >>> ./libavutil/mem.h:342:1: warning: 'alloc_size' attribute ignored on a function returning int' [-Wattributes] >>> 342 | av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); >>> | ^~~~~~~~~~~~~ >> >> Is the attribute also useless on all other compilers ? > > The attribute is only used when __GNUC__ is defined, so it should for > any such compiler (GCC and Clang). > > https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > The Clang documentation does note a minor difference from GCC, but both GCC and Clang agree that it applies to functions that return a pointer. The size is the number of bytes allocated at that pointer. It doesn't support an indirect reference to the allocated memory; if it did it would likely need an additional parameter to indicate which argument was the indirect reference. https://clang.llvm.org/docs/AttributeReference.html#alloc-size - Mark
On Sun, Nov 25, 2018 at 05:55:37PM -0800, Mark Harris wrote: > On 2018-11-25 17:29, James Almer wrote: > > On 11/25/2018 10:01 PM, Michael Niedermayer wrote: > >> On Sat, Nov 24, 2018 at 01:02:02PM -0800, Mark Harris wrote: > >>> The alloc_size attribute is valid only on functions that return a > >>> pointer. GCC 9 (not yet released) warns about invalid usage: > >>> > >>> ./libavutil/mem.h:342:1: warning: 'alloc_size' attribute ignored on a function returning int' [-Wattributes] > >>> 342 | av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); > >>> | ^~~~~~~~~~~~~ > >> > >> Is the attribute also useless on all other compilers ? > > > > The attribute is only used when __GNUC__ is defined, so it should for > > any such compiler (GCC and Clang). > > > > https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > > > > The Clang documentation does note a minor difference from GCC, but both > GCC and Clang agree that it applies to functions that return a pointer. > The size is the number of bytes allocated at that pointer. It doesn't > support an indirect reference to the allocated memory; if it did it > would likely need an additional parameter to indicate which argument was > the indirect reference. ok, will apply thx [...]
diff --git a/libavutil/mem.h b/libavutil/mem.h index 55ae573ac9..5fb1a02dd9 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -339,7 +339,7 @@ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size) * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be * correctly aligned. */ -av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); +int av_reallocp_array(void *ptr, size_t nmemb, size_t size); /** * Reallocate the given buffer if it is not large enough, otherwise do nothing.