From 61a1e5d4835dffd7f352e05e25f798fb3c178179 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Mon, 3 Oct 2016 18:59:12 +0200 Subject: [PATCH] examples/: return 1 if object creation failed --- examples/aubiomfcc.c | 9 +++++++-- examples/aubionotes.c | 7 +++++-- examples/aubioonset.c | 5 ++++- examples/aubiopitch.c | 6 ++++-- examples/aubiotrack.c | 6 ++++-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/examples/aubiomfcc.c b/examples/aubiomfcc.c index d8bb9102..0942ade7 100644 --- a/examples/aubiomfcc.c +++ b/examples/aubiomfcc.c @@ -48,6 +48,7 @@ void process_print (void) } int main(int argc, char **argv) { + int ret = 0; // change some default params buffer_size = 512; hop_size = 256; @@ -62,6 +63,10 @@ int main(int argc, char **argv) { fftgrain = new_cvec (buffer_size); mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate); mfcc_out = new_fvec(n_coefs); + if (pv == NULL || fftgrain == NULL || mfcc == NULL || mfcc_out == NULL) { + ret = 1; + goto beach; + } examples_common_process((aubio_process_func_t)process_block, process_print); @@ -70,7 +75,7 @@ int main(int argc, char **argv) { del_aubio_mfcc(mfcc); del_fvec(mfcc_out); +beach: examples_common_del(); - return 0; + return ret; } - diff --git a/examples/aubionotes.c b/examples/aubionotes.c index 9e8149f2..5b3c44ed 100644 --- a/examples/aubionotes.c +++ b/examples/aubionotes.c @@ -50,6 +50,8 @@ void process_print (void) } int main(int argc, char **argv) { + int ret = 0; + examples_common_init(argc,argv); verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); @@ -65,6 +67,7 @@ int main(int argc, char **argv) { verbmsg ("tolerance: %f\n", pitch_tolerance); notes = new_aubio_notes ("default", buffer_size, hop_size, samplerate); + if (notes == NULL) { ret = 1; goto beach; } examples_common_process((aubio_process_func_t)process_block, process_print); @@ -73,7 +76,7 @@ int main(int argc, char **argv) { del_aubio_notes (notes); +beach: examples_common_del(); - return 0; + return ret; } - diff --git a/examples/aubioonset.c b/examples/aubioonset.c index 3d00576a..bf996a4a 100644 --- a/examples/aubioonset.c +++ b/examples/aubioonset.c @@ -58,6 +58,7 @@ void process_print (void) } int main(int argc, char **argv) { + int ret = 0; examples_common_init(argc,argv); verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); @@ -68,6 +69,7 @@ int main(int argc, char **argv) { verbmsg ("threshold: %f\n", onset_threshold); o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate); + if (o == NULL) { ret = 1; goto beach; } if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold); if (silence_threshold != -90.) @@ -88,6 +90,7 @@ int main(int argc, char **argv) { del_aubio_wavetable (wavetable); del_fvec (onset); +beach: examples_common_del(); - return 0; + return ret; } diff --git a/examples/aubiopitch.c b/examples/aubiopitch.c index 73ed27c8..2d7a0122 100644 --- a/examples/aubiopitch.c +++ b/examples/aubiopitch.c @@ -52,6 +52,7 @@ void process_print (void) } int main(int argc, char **argv) { + int ret = 0; buffer_size = 2048; @@ -65,6 +66,7 @@ int main(int argc, char **argv) { verbmsg ("tolerance: %f\n", pitch_tolerance); o = new_aubio_pitch (pitch_method, buffer_size, hop_size, samplerate); + if (o == NULL) { ret = 1; goto beach; } if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (o, pitch_tolerance); if (silence_threshold != -90.) @@ -83,7 +85,7 @@ int main(int argc, char **argv) { del_aubio_wavetable (wavetable); del_fvec (pitch); +beach: examples_common_del(); - return 0; + return ret; } - diff --git a/examples/aubiotrack.c b/examples/aubiotrack.c index f6087b55..8667b01c 100644 --- a/examples/aubiotrack.c +++ b/examples/aubiotrack.c @@ -60,6 +60,7 @@ void process_print (void) { } int main(int argc, char **argv) { + int ret = 0; // override general settings from utils.c buffer_size = 1024; hop_size = 512; @@ -75,6 +76,7 @@ int main(int argc, char **argv) { tempo_out = new_fvec(2); tempo = new_aubio_tempo(tempo_method, buffer_size, hop_size, samplerate); + if (tempo == NULL) { ret = 1; goto beach; } // set silence threshold very low to output beats even during silence // aubio_tempo_set_silence(tempo, -1000.); if (onset_threshold != 0.) aubio_tempo_set_threshold (tempo, onset_threshold); @@ -92,7 +94,7 @@ int main(int argc, char **argv) { del_aubio_wavetable (wavetable); del_fvec(tempo_out); +beach: examples_common_del(); - return 0; + return ret; } - -- 2.11.0