Merge commit 'c3bd1d60af97e8d2568dac9fcce7bdabb4ff93c8'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 12 Mar 2015 21:39:27 +0000 (22:39 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 12 Mar 2015 21:40:56 +0000 (22:40 +0100)
* commit 'c3bd1d60af97e8d2568dac9fcce7bdabb4ff93c8':
  formats: Check memory allocations

Conflicts:
libavfilter/formats.c

See: 527ca3985c736ffe077a82fdf3616f0fd571b923
Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavfilter/formats.c

@@@ -262,51 -162,26 +262,52 @@@ int ff_fmt_is_in(int fmt, const int *fm
      return 0;
  }
  
-     if (!formats) return NULL;                                          \
 +#define COPY_INT_LIST(list_copy, list, type) {                          \
 +    int count = 0;                                                      \
 +    if (list)                                                           \
 +        for (count = 0; list[count] != -1; count++)                     \
 +            ;                                                           \
 +    list_copy = av_calloc(count+1, sizeof(type));                       \
 +    if (list_copy) {                                                    \
 +        memcpy(list_copy, list, sizeof(type) * count);                  \
 +        list_copy[count] = -1;                                          \
 +    }                                                                   \
 +}
 +
 +#define MAKE_FORMAT_LIST(type, field, count_field)                      \
 +    type *formats;                                                      \
 +    int count = 0;                                                      \
 +    if (fmts)                                                           \
 +        for (count = 0; fmts[count] != -1; count++)                     \
 +            ;                                                           \
 +    formats = av_mallocz(sizeof(*formats));                             \
-             av_free(formats);                                           \
++    if (!formats)                                                       \
++        return NULL;                                                    \
 +    formats->count_field = count;                                       \
 +    if (count) {                                                        \
 +        formats->field = av_malloc_array(count, sizeof(*formats->field));      \
 +        if (!formats->field) {                                          \
++            av_freep(&formats);                                         \
 +            return NULL;                                                \
 +        }                                                               \
 +    }
 +
  AVFilterFormats *ff_make_format_list(const int *fmts)
  {
 -    AVFilterFormats *formats;
 -    int count;
 +    MAKE_FORMAT_LIST(AVFilterFormats, formats, nb_formats);
 +    while (count--)
 +        formats->formats[count] = fmts[count];
  
 -    for (count = 0; fmts[count] != -1; count++)
 -        ;
 +    return formats;
 +}
  
 -    formats               = av_mallocz(sizeof(*formats));
 -    if (!formats)
 -        return NULL;
 -    if (count) {
 -        formats->formats  = av_malloc(sizeof(*formats->formats) * count);
 -        if (!formats->formats) {
 -            av_freep(&formats);
 -            return NULL;
 -        }
 -    }
 -    formats->nb_formats = count;
 -    memcpy(formats->formats, fmts, sizeof(*formats->formats) * count);
 +AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts)
 +{
 +    MAKE_FORMAT_LIST(AVFilterChannelLayouts,
 +                     channel_layouts, nb_channel_layouts);
 +    if (count)
 +        memcpy(formats->channel_layouts, fmts,
 +               sizeof(*formats->channel_layouts) * count);
  
      return formats;
  }