aboutsummaryrefslogtreecommitdiff
path: root/fft.c
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2013-09-03 01:19:16 +0000
committerDimitri Sokolyuk <demon@dim13.org>2013-09-03 01:19:16 +0000
commiteb9e72e645583932d0b3010e7d49a16e55170f04 (patch)
tree6d891bf3d910444dc0b7c2611240b88290f83eb8 /fft.c
parent0e0e2b41fb5a372a8f0714efed29bd1c75d8a0a1 (diff)
add more error handling
Diffstat (limited to 'fft.c')
-rw-r--r--fft.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/fft.c b/fft.c
index 1e0e426..d178a84 100644
--- a/fft.c
+++ b/fft.c
@@ -46,19 +46,26 @@ hamming(size_t n)
return w;
}
+double *
+fft_realloc(double *p, size_t n)
+{
+ if (p)
+ fftw_free(p);
+ p = fftw_malloc(n * sizeof(double));
+ if (!p)
+ errx(1, "malloc failed");
+
+ return p;
+}
+
struct fft *
resize_fft(struct fft *p, size_t n)
{
if (n != p->n) {
p->n = n;
- if (p->in)
- fftw_free(p->in);
- p->in = fftw_malloc(p->n * sizeof(double));
-
- if (p->out)
- fftw_free(p->out);
- p->out = fftw_malloc(p->n * sizeof(double));
+ p->in = fft_realloc(p->in, p->n);
+ p->out = fft_realloc(p->out, p->n);
if (p->window)
free(p->window);