From abffec017c01c96f6aa7ade82c7b7a4c2ff0b56d Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 20 Aug 2015 17:22:05 +0200 Subject: [PATCH] tests/src/test-delnull.c: improve test, avoid segfaults --- tests/src/test-delnull.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/src/test-delnull.c b/tests/src/test-delnull.c index 6a0afc41..bb245090 100644 --- a/tests/src/test-delnull.c +++ b/tests/src/test-delnull.c @@ -1,13 +1,24 @@ #include #include "aubio.h" -// Because aubio does not check for double free, this program will crash. -// Programs that call these functions should check for null pointers. +// When creating an aubio object, the user should check whether the object is +// set NULL, indicating the creation failed and the object was not allocated. int main (void) { - del_fvec(NULL); - del_lvec(NULL); - del_cvec(NULL); - return 0; + uint_t return_code = 0; + fvec_t *f = new_fvec(-12); + cvec_t *c = new_cvec(-12); + lvec_t *l = new_lvec(-12); + aubio_fft_t *fft = new_aubio_fft(-12); + if (f != NULL) { + return_code = 1; + } else if (c != NULL) { + return_code = 2; + } else if (l != NULL) { + return_code = 3; + } else if (fft != NULL) { + return_code = 3; + } + return return_code; } -- 2.11.0