shithub: aubio

Download patch

ref: 892c36931e1ee7d478457119c30237b2e249673b
parent: 2abe563da12759fb6a44fa4b8b52a60f5abd3449
author: Paul Brossier <piem@piem.org>
date: Sat Sep 20 06:23:52 EDT 2014

src/onset/onset.c: check parameters

--- a/src/onset/onset.c
+++ b/src/onset/onset.c
@@ -172,6 +172,22 @@
     uint_t buf_size, uint_t hop_size, uint_t samplerate)
 {
   aubio_onset_t * o = AUBIO_NEW(aubio_onset_t);
+
+  /* check parameters are valid */
+  if ((sint_t)hop_size < 1) {
+    AUBIO_ERR("onset: got hop_size %d, but can not be < 1\n", hop_size);
+    goto beach;
+  } else if ((sint_t)buf_size < 1) {
+    AUBIO_ERR("onset: got buffer_size %d, but can not be < 1\n", buf_size);
+    goto beach;
+  } else if (buf_size < hop_size) {
+    AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", buf_size, hop_size);
+    goto beach;
+  } else if ((sint_t)samplerate < 1) {
+    AUBIO_ERR("onset: samplerate (%d) can not be < 1\n", samplerate);
+    goto beach;
+  }
+
   /* store creation parameters */
   o->samplerate = samplerate;
   o->hop_size = hop_size;
@@ -193,6 +209,10 @@
   o->last_onset = 0;
   o->total_frames = 0;
   return o;
+
+beach:
+  AUBIO_FREE(o);
+  return NULL;
 }
 
 void del_aubio_onset (aubio_onset_t *o)