]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/mem.h
Fix the logic to access the location of a string to free when setting
[ffmpeg] / libavutil / mem.h
index 851d1408a0d9bc2e141cc802fde7f09d862633bb..84d647d8ead861962c1b9751f75b188f85fc5350 100644 (file)
 #define FFMPEG_MEM_H
 
 #ifdef __ICC
-  #define DECLARE_ALIGNED(n,t,v)       t v __attribute__ ((aligned (n)))
-  #define DECLARE_ASM_CONST(n,t,v)     const t __attribute__ ((aligned (n))) v
-#elif __GNUC__
-  #define DECLARE_ALIGNED(n,t,v)       t v __attribute__ ((aligned (n)))
-  #define DECLARE_ASM_CONST(n,t,v)     static const t v attribute_used __attribute__ ((aligned (n)))
-#elif _MSVC
-  #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
-  #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
+    #define DECLARE_ALIGNED(n,t,v)      t v __attribute__ ((aligned (n)))
+    #define DECLARE_ASM_CONST(n,t,v)    const t __attribute__ ((aligned (n))) v
+#elif defined(__GNUC__)
+    #define DECLARE_ALIGNED(n,t,v)      t v __attribute__ ((aligned (n)))
+    #define DECLARE_ASM_CONST(n,t,v)    static const t v attribute_used __attribute__ ((aligned (n)))
+#elif defined(_MSC_VER)
+    #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
+    #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
+#elif defined(HAVE_INLINE_ASM)
+    #error The asm code needs alignment, but we do not know how to do it for this compiler.
+#else
+    #define DECLARE_ALIGNED(n,t,v)      t v
+    #define DECLARE_ASM_CONST(n,t,v)    static const t v
+#endif
+
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+    #define av_malloc_attrib __attribute__((__malloc__))
+#else
+    #define av_malloc_attrib
+#endif
+
+#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
+    #define av_alloc_size(n) __attribute__((alloc_size(n)))
+#else
+    #define av_alloc_size(n)
 #endif
 
 /**
@@ -45,7 +62,7 @@
  * it.
  * @see av_mallocz()
  */
-void *av_malloc(unsigned int size);
+void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
 
 /**
  * Allocate or reallocate a block of memory.
@@ -59,7 +76,7 @@ void *av_malloc(unsigned int size);
  * reallocate or the function is used to free the memory block.
  * @see av_fast_realloc()
  */
-void *av_realloc(void *ptr, unsigned int size);
+void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
 
 /**
  * Free a memory block which has been allocated with av_malloc(z)() or
@@ -80,7 +97,7 @@ void av_free(void *ptr);
  * it.
  * @see av_malloc()
  */
-void *av_mallocz(unsigned int size);
+void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
 
 /**
  * Duplicate the string \p s.
@@ -88,7 +105,7 @@ void *av_mallocz(unsigned int size);
  * @return Pointer to a newly allocated string containing a
  * copy of \p s or NULL if it cannot be allocated.
  */
-char *av_strdup(const char *s);
+char *av_strdup(const char *s) av_malloc_attrib;
 
 /**
  * Free a memory block which has been allocated with av_malloc(z)() or