diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-12-03 14:34:47 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-12-05 13:27:38 +0100 |
commit | 2e7ef008e312bde7c151034628adc2da04313566 (patch) | |
tree | 501f672547c0a2d4f6b5e05e347b083db21cd958 /fftools | |
parent | 9d73967b40231b27504cb86ea177887be03bb328 (diff) | |
download | ffmpeg-2e7ef008e312bde7c151034628adc2da04313566.tar.gz |
fftools/cmdutils: Make allocate_array_elem() return ptr to new element
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'fftools')
-rw-r--r-- | fftools/cmdutils.c | 6 | ||||
-rw-r--r-- | fftools/cmdutils.h | 4 | ||||
-rw-r--r-- | fftools/ffmpeg_filter.c | 13 | ||||
-rw-r--r-- | fftools/ffmpeg_opt.c | 9 |
4 files changed, 13 insertions, 19 deletions
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 1464b122df..0b57552e5c 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -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) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index ae78e60f4c..82cda208be 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -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); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 7263ea5f03..501a0acd61 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -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; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index bd1d451ff7..eea57a6974 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -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; @@ -2260,8 +2259,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; @@ -3278,8 +3276,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; |