@@ -2216,8 +2216,9 @@ void *grow_array(void *array, int elem_size, int *size, int new_size)
void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
{
- void *new_elem, **array = (void**)ptr;
+ void *new_elem, **array;
+ memcpy(&array, ptr, sizeof(array));
if (*nb_elems == INT_MAX) {
av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
exit_program(1);
@@ -2226,8 +2227,9 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
if (!new_elem)
exit_program(1);
GROW_ARRAY(array, *nb_elems);
+ memcpy(ptr, &array, sizeof(array));
array[*nb_elems - 1] = new_elem;
- return array;
+ return new_elem;
}
double get_rotation(int32_t *displaymatrix)
@@ -638,7 +638,7 @@ void *grow_array(void *array, int elem_size, int *size, int new_size);
* @param elem_size size of the new element to allocate
* @param nb_elems pointer to the number of elements of the array array;
* *nb_elems will be incremented by one by this function.
- * @return reallocated array
+ * @return pointer to the newly allocated entry
*/
void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
@@ -648,7 +648,7 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
#define ALLOC_ARRAY_ELEM(array, nb_elems)\
- array = allocate_array_elem(array, sizeof(*array[0]), &nb_elems)
+ allocate_array_elem(&array, sizeof(*array[0]), &nb_elems)
#define GET_PIX_FMT_NAME(pix_fmt)\
const char *name = av_get_pix_fmt_name(pix_fmt);
@@ -166,16 +166,14 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
exit_program(1);
fg->index = nb_filtergraphs;
- ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
- ofilter = fg->outputs[0];
+ ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
ofilter->ost = ost;
ofilter->graph = fg;
ofilter->format = -1;
ost->filter = ofilter;
- ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
- ifilter = fg->inputs[0];
+ ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
ifilter->ist = ist;
ifilter->graph = fg;
ifilter->format = -1;
@@ -281,8 +279,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
ist->decoding_needed |= DECODING_FOR_FILTER;
ist->st->discard = AVDISCARD_NONE;
- ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
- ifilter = fg->inputs[fg->nb_inputs - 1];
+ ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
ifilter->ist = ist;
ifilter->graph = fg;
ifilter->format = -1;
@@ -318,9 +315,7 @@ int init_complex_filtergraph(FilterGraph *fg)
init_input_filter(fg, cur);
for (cur = outputs; cur;) {
- OutputFilter *ofilter;
- ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
- ofilter = fg->outputs[fg->nb_outputs - 1];
+ OutputFilter *const ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
ofilter->graph = fg;
ofilter->out_tmp = cur;
@@ -1265,8 +1265,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
/* dump the file content */
av_dump_format(ic, nb_input_files, filename, 0);
- ALLOC_ARRAY_ELEM(input_files, nb_input_files);
- f = input_files[nb_input_files - 1];
+ f = ALLOC_ARRAY_ELEM(input_files, nb_input_files);
f->ctx = ic;
f->ist_index = nb_input_streams - ic->nb_streams;
@@ -2258,8 +2257,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
}
}
- ALLOC_ARRAY_ELEM(output_files, nb_output_files);
- of = output_files[nb_output_files - 1];
+ of = ALLOC_ARRAY_ELEM(output_files, nb_output_files);
of->ost_index = nb_output_streams;
of->recording_time = o->recording_time;
@@ -3276,8 +3274,7 @@ static int opt_filter_complex_script(void *optctx, const char *opt, const char *
if (!graph_desc)
return AVERROR(EINVAL);
- ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
- fg = filtergraphs[nb_filtergraphs - 1];
+ fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
fg->index = nb_filtergraphs - 1;
fg->graph_desc = graph_desc;
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- fftools/cmdutils.c | 6 ++++-- fftools/cmdutils.h | 4 ++-- fftools/ffmpeg_filter.c | 13 ++++--------- fftools/ffmpeg_opt.c | 9 +++------ 4 files changed, 13 insertions(+), 19 deletions(-)