[filterbank] validate input parameters
[aubio.git] / src / spectral / filterbank.c
index 5497a4f..fb82ec0 100644 (file)
@@ -42,6 +42,15 @@ new_aubio_filterbank (uint_t n_filters, uint_t win_s)
 {
   /* allocate space for filterbank object */
   aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t);
+
+  if ((sint_t)n_filters <= 0) {
+    AUBIO_ERR("filterbank: n_filters should be > 0, got %d\n", n_filters);
+    goto fail;
+  }
+  if ((sint_t)win_s <= 0) {
+    AUBIO_ERR("filterbank: win_s should be > 0, got %d\n", win_s);
+    goto fail;
+  }
   fb->win_s = win_s;
   fb->n_filters = n_filters;
 
@@ -53,6 +62,9 @@ new_aubio_filterbank (uint_t n_filters, uint_t win_s)
   fb->power = 1;
 
   return fb;
+fail:
+  AUBIO_FREE (fb);
+  return NULL;
 }
 
 void