shithub: aubio

Download patch

ref: 767990ea552e77c6fb4c80e53455d64cc7adbfa0
parent: 41eff53cc1f9878d7655f5d86e37373970f4b158
author: Paul Brossier <piem@piem.org>
date: Thu Nov 28 10:51:15 EST 2013

src/{fvec,cvec,lvec,fmat}.c: make sure new_ functions return NULL if length <= 0

--- a/src/cvec.c
+++ b/src/cvec.c
@@ -22,6 +22,9 @@
 #include "cvec.h"
 
 cvec_t * new_cvec( uint_t length) {
+  if ((sint_t)length <= 0) {
+    return NULL;
+  }
   cvec_t * s = AUBIO_NEW(cvec_t);
   s->length = length/2 + 1;
   s->norm = AUBIO_ARRAY(smpl_t,s->length);
--- a/src/fmat.c
+++ b/src/fmat.c
@@ -22,6 +22,9 @@
 #include "fmat.h"
 
 fmat_t * new_fmat (uint_t length, uint_t height) {
+  if ((sint_t)length <= 0 || (sint_t)height <= 0 ) {
+    return NULL;
+  }
   fmat_t * s = AUBIO_NEW(fmat_t);
   uint_t i,j;
   s->height = height;
--- a/src/fvec.c
+++ b/src/fvec.c
@@ -22,6 +22,9 @@
 #include "fvec.h"
 
 fvec_t * new_fvec( uint_t length) {
+  if ((sint_t)length <= 0) {
+    return NULL;
+  }
   fvec_t * s = AUBIO_NEW(fvec_t);
   s->length = length;
   s->data = AUBIO_ARRAY(smpl_t, s->length);
--- a/src/lvec.c
+++ b/src/lvec.c
@@ -22,6 +22,9 @@
 #include "lvec.h"
 
 lvec_t * new_lvec( uint_t length) {
+  if ((sint_t)length <= 0) {
+    return NULL;
+  }
   lvec_t * s = AUBIO_NEW(lvec_t);
   s->length = length;
   s->data = AUBIO_ARRAY(lsmp_t, s->length);
--