# HG changeset patch # User Jamie Bullock # Date 1394230495 0 # Node ID f262144347e7fe7a8b0ebe81e21d94b2350b98c6 # Parent 302eab34dc88046061906b1467629ad070eef51b Return XTRACT_ARGUMENT_ERROR if we try to initialise an mel filter bank with less than 2 bands diff -r 302eab34dc88 -r f262144347e7 src/init.c --- a/src/init.c Fri Mar 07 22:14:04 2014 +0000 +++ b/src/init.c Fri Mar 07 22:14:55 2014 +0000 @@ -251,6 +251,11 @@ fft_peak = NULL; norm = 1; + if (freq_bands <= 1) + { + return XTRACT_ARGUMENT_ERROR; + } + mel_freq_max = 1127 * log(1 + freq_max / 700); mel_freq_min = 1127 * log(1 + freq_min / 700); freq_bw_mel = (mel_freq_max - mel_freq_min) / freq_bands; @@ -269,6 +274,7 @@ if (lin_peak == NULL) { perror("error"); + free(mel_peak); return XTRACT_MALLOC_FAILED; } @@ -277,6 +283,8 @@ if (fft_peak == NULL) { perror("error"); + free(mel_peak); + free(lin_peak); return XTRACT_MALLOC_FAILED; } @@ -285,6 +293,9 @@ if (height_norm == NULL) { perror("error"); + free(mel_peak); + free(lin_peak); + free(fft_peak); return XTRACT_MALLOC_FAILED; } @@ -295,7 +306,7 @@ fft_peak[0] = lin_peak[0] / nyquist * M; - for (n = 1; n < freq_bands + 2; n++) + for (n = 1; n < (freq_bands + 2); ++n) { //roll out peak locations - mel, linear and linear on fft window scale mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;