From 65d05c1d92ea36886d76c5c9af6c65b444d6a3bc Mon Sep 17 00:00:00 2001 From: DRC Date: Thu, 18 Feb 2010 00:40:17 +0000 Subject: [PATCH] Exit with non-zero status if an error is encountered git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@121 632fc199-4ca6-4c93-a231-07263d6284db --- jpegut.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/jpegut.c b/jpegut.c index 3b02fba3..91b36413 100644 --- a/jpegut.c +++ b/jpegut.c @@ -19,11 +19,14 @@ #include "./rrtimer.h" #include "./turbojpeg.h" -#define _catch(f) {if((f)==-1) {printf("TJPEG: %s\n", tjGetErrorStr()); goto finally;}} +#define _catch(f) {if((f)==-1) {printf("TJPEG: %s\n", tjGetErrorStr()); bailout();}} const char *_subnamel[NUMSUBOPT]={"4:4:4", "4:2:2", "4:2:0", "GRAY"}; const char *_subnames[NUMSUBOPT]={"444", "422", "420", "GRAY"}; +int exitstatus=0; +#define bailout() {exitstatus=-1; goto finally;} + int pixels[9][3]= { {0, 255, 0}, @@ -177,12 +180,12 @@ void writejpeg(unsigned char *jpegbuf, unsigned long jpgbufsize, char *filename) if((outfile=fopen(filename, "wb"))==NULL) { printf("ERROR: Could not open %s for writing.\n", filename); - goto finally; + bailout(); } if(fwrite(jpegbuf, jpgbufsize, 1, outfile)!=1) { printf("ERROR: Could not write to %s.\n", filename); - goto finally; + bailout(); } finally: @@ -210,7 +213,7 @@ void gentestjpeg(tjhandle hnd, unsigned char *jpegbuf, unsigned long *size, if((bmpbuf=(unsigned char *)malloc(w*h*ps+1))==NULL) { - printf("ERROR: Could not allocate buffer\n"); goto finally; + printf("ERROR: Could not allocate buffer\n"); bailout(); } initbuf(bmpbuf, w, h, ps, flags); memset(jpegbuf, 0, TJBUFSIZE(w, h)); @@ -249,12 +252,12 @@ void gentestbmp(tjhandle hnd, unsigned char *jpegbuf, unsigned long jpegsize, _catch(tjDecompressHeader(hnd, jpegbuf, jpegsize, &_w, &_h)); if(_w!=w || _h!=h) { - printf("Incorrect JPEG header\n"); goto finally; + printf("Incorrect JPEG header\n"); bailout(); } if((bmpbuf=(unsigned char *)malloc(w*h*ps+1))==NULL) { - printf("ERROR: Could not allocate buffer\n"); goto finally; + printf("ERROR: Could not allocate buffer\n"); bailout(); } memset(bmpbuf, 0, w*ps*h); @@ -278,13 +281,13 @@ void dotest(int w, int h, int ps, int subsamp, char *basefilename) if((jpegbuf=(unsigned char *)malloc(TJBUFSIZE(w, h))) == NULL) { - puts("ERROR: Could not allocate buffer."); goto finally; + puts("ERROR: Could not allocate buffer."); bailout(); } if((hnd=tjInitCompress())==NULL) - {printf("Error in tjInitCompress():\n%s\n", tjGetErrorStr()); goto finally;} + {printf("Error in tjInitCompress():\n%s\n", tjGetErrorStr()); bailout();} if((dhnd=tjInitDecompress())==NULL) - {printf("Error in tjInitDecompress():\n%s\n", tjGetErrorStr()); goto finally;} + {printf("Error in tjInitDecompress():\n%s\n", tjGetErrorStr()); bailout();} gentestjpeg(hnd, jpegbuf, &size, w, h, ps, basefilename, subsamp, 100, 0); gentestbmp(dhnd, jpegbuf, size, w, h, ps, basefilename, subsamp, 100, 0); @@ -327,7 +330,7 @@ void dotest1(void) int i, j, i2; unsigned char *bmpbuf=NULL, *jpgbuf=NULL; tjhandle hnd=NULL; unsigned long size; if((hnd=tjInitCompress())==NULL) - {printf("Error in tjInitCompress():\n%s\n", tjGetErrorStr()); goto finally;} + {printf("Error in tjInitCompress():\n%s\n", tjGetErrorStr()); bailout();} printf("Buffer size regression test\n"); for(j=1; j<48; j++) { @@ -337,7 +340,7 @@ void dotest1(void) if((bmpbuf=(unsigned char *)malloc(i*j*4))==NULL || (jpgbuf=(unsigned char *)malloc(TJBUFSIZE(i, j)))==NULL) { - printf("Memory allocation failure\n"); goto finally; + printf("Memory allocation failure\n"); bailout(); } memset(bmpbuf, 0, i*j*4); for(i2=0; i2