From d2114c3f2e0217801482e24782ade917ce028d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Tue, 18 Jan 2022 21:10:31 +0100 Subject: [PATCH] spa: audioconvert: fix allocation size calculation Currently, the code allocates sizeof(header) * sizeof(item) * n_items bytes instead of the more appropriate sizeof(header) + sizeof(item) * n_items Fix that by simply changing the first multiplication to addition, and furthermore, use a flexible array member instead of a zero-sized array. Found by clang-tidy. --- spa/plugins/audioconvert/resample-peaks-impl.h | 2 +- spa/plugins/audioconvert/resample-peaks.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spa/plugins/audioconvert/resample-peaks-impl.h b/spa/plugins/audioconvert/resample-peaks-impl.h index 86cb71799..d8b28fb2b 100644 --- a/spa/plugins/audioconvert/resample-peaks-impl.h +++ b/spa/plugins/audioconvert/resample-peaks-impl.h @@ -31,7 +31,7 @@ struct peaks_data { uint32_t o_count; uint32_t i_count; - float max_f[0]; + float max_f[]; }; #if defined (HAVE_SSE) diff --git a/spa/plugins/audioconvert/resample-peaks.c b/spa/plugins/audioconvert/resample-peaks.c index b1663a3c4..9e4c4223d 100644 --- a/spa/plugins/audioconvert/resample-peaks.c +++ b/spa/plugins/audioconvert/resample-peaks.c @@ -146,7 +146,7 @@ int resample_peaks_init(struct resample *r) r->delay = impl_peaks_delay; r->in_len = impl_peaks_in_len; - d = r->data = calloc(1, sizeof(struct peaks_data) * sizeof(float) * r->channels); + d = r->data = calloc(1, sizeof(struct peaks_data) + sizeof(float) * r->channels); if (r->data == NULL) return -errno;