On 9/4/13 12:36 PM, Diego Biurrun wrote:
---
  libavutil/mem.c |    4 ++--
  libavutil/mem.h |   30 ++++++++++++++----------------
  2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index e901533..b4a190a 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -65,7 +65,7 @@ void *av_malloc(size_t size)
      long diff;
  #endif

-    /* let's disallow possible ambiguous cases */
+    /* let's disallow possibly ambiguous cases */
      if (size > (INT_MAX - 32) || !size)
          return NULL;

@@ -119,7 +119,7 @@ void *av_realloc(void *ptr, size_t size)
      int diff;
  #endif

-    /* let's disallow possible ambiguous cases */
+    /* let's disallow possibly ambiguous cases */
      if (size > (INT_MAX - 16))
          return NULL;

diff --git a/libavutil/mem.h b/libavutil/mem.h
index e472a3f..5eae3cf 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -82,8 +82,7 @@
  void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);

  /**
- * Helper function to allocate a block of size * nmemb bytes with
- * using av_malloc()
+ * Allocate a block of size * nmemb bytes with av_malloc().
   * @param nmemb Number of elements
   * @param size Size of the single element
   * @return Pointer to the allocated block, NULL if the block cannot
@@ -101,14 +100,14 @@ av_alloc_size(1, 2) static inline void 
*av_malloc_array(size_t nmemb, size_t siz
   * Allocate or reallocate a block of memory.
   * If ptr is NULL and size > 0, allocate a new block. If
   * size is zero, free the memory block pointed to by ptr.
- * @note Pointers provided by av_malloc family of functions cannot be
- * passed to av_realloc().
   * @param ptr Pointer to a memory block already allocated with
   * av_realloc() or NULL.
- * @param size Size in bytes for the memory block to be allocated or
+ * @param size Size in bytes of the memory block to be allocated or
   * reallocated.
- * @return Pointer to a newly reallocated block or NULL if the block
+ * @return Pointer to a newly-reallocated block or NULL if the block
   * cannot be reallocated or the function is used to free the memory block.
+ * @note av_realloc() is not guaranteed to maintain the alignment of
+ *       pointers originating from the av_malloc() family of functions.

As pointed by Martin, this is WRONG.

If you pass a pointer allocated by memalign to realloc it SHOULD CRASH or cause horrid corruptions.

Shame on me for not noticing.

lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to