On Mon, 29 Jul 2013, Alexandra Khirnova wrote:

---
libavformat/cutils.c   |    7 +++++--
libavformat/internal.h |    8 +++++---
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/libavformat/cutils.c b/libavformat/cutils.c
index f58e152..ebcc751 100644
--- a/libavformat/cutils.c
+++ b/libavformat/cutils.c
@@ -22,7 +22,7 @@
#include "internal.h"

/* add one element to a dynamic array */
-void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
+int ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
{
    /* see similar avconv.c:grow_array() */
    int nb, nb_alloc;
@@ -35,11 +35,14 @@ void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, 
intptr_t elem)
            nb_alloc = 1;
        else
            nb_alloc = nb * 2;
-        tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
+        if (av_reallocp(&tab, nb_alloc * sizeof(intptr_t)) < 0)
+            return AVERROR(ENOMEM);
        *tab_ptr = tab;
    }
    tab[nb++] = elem;
    *nb_ptr = nb;
+
+    return 0;
}

#define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0))
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 1bc3e51..68098bb 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -42,7 +42,7 @@ typedef struct CodecMime{
    enum AVCodecID id;
} CodecMime;

-void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
+int ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);

#ifdef __GNUC__
#define dynarray_add(tab, nb_ptr, elem)\
@@ -50,12 +50,14 @@ do {\
    __typeof__(tab) _tab = (tab);\
    __typeof__(elem) _elem = (elem);\
    (void)sizeof(**_tab == _elem); /* check that types are compatible */\
-    ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
+    if (ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem) < 0)\
+    return AVERROR(ENOMEM);                                             \

This is a macro; you can't add a return in the middle of a macro - that won't give the caller a chance to actually handle it properly.

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

Reply via email to