src/{fvec,cvec,lvec,fmat}.c: make sure new_ functions return NULL if length <= 0
authorPaul Brossier <piem@piem.org>
Thu, 28 Nov 2013 20:51:15 +0000 (15:51 -0500)
committerPaul Brossier <piem@piem.org>
Thu, 28 Nov 2013 20:51:15 +0000 (15:51 -0500)
src/cvec.c
src/fmat.c
src/fvec.c
src/lvec.c

index efc89f8..3439810 100644 (file)
@@ -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);
index 7c0e928..ec373e1 100644 (file)
@@ -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;
index e62810e..80a50e3 100644 (file)
@@ -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);
index cab6802..69d0f03 100644 (file)
@@ -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);