summaryrefslogtreecommitdiff
path: root/fftools/cmdutils.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-03 14:56:30 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-05 13:27:38 +0100
commit2d0bfbd0fafe5e869919120758903801f91530fa (patch)
treefd15f33588dcabf7d4c3cec2d93554857948e259 /fftools/cmdutils.c
parent2e7ef008e312bde7c151034628adc2da04313566 (diff)
downloadffmpeg-2d0bfbd0fafe5e869919120758903801f91530fa.tar.gz
fftools/cmdutils: Use av_dynarray_add_nofree()
Simplifies code and reduces the number of allocations a bit by overallocating. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'fftools/cmdutils.c')
-rw-r--r--fftools/cmdutils.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 0b57552e5c..3c8e5a82cd 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -2216,19 +2216,13 @@ 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 *new_elem;
- memcpy(&array, ptr, sizeof(array));
- if (*nb_elems == INT_MAX) {
- av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
+ if (!(new_elem = av_mallocz(elem_size)) ||
+ av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
exit_program(1);
}
- new_elem = av_mallocz(elem_size);
- if (!new_elem)
- exit_program(1);
- GROW_ARRAY(array, *nb_elems);
- memcpy(ptr, &array, sizeof(array));
- array[*nb_elems - 1] = new_elem;
return new_elem;
}