rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit d34aeecf2ef0463e6b40819432b37371afc2f122
parent 3218162ed6a43570f9cfb80281018f2f68b5af4e
Author: vaplv <vaplv@free.fr>
Date:   Wed, 30 Apr 2014 07:59:37 +0200

Fix the image_ppm_write return value when an error occurs

Diffstat:
Msrc/image.c | 20+++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/image.c b/src/image.c @@ -26,17 +26,12 @@ image_ppm_write #define FWRITE(Fp, String) \ { \ const size_t i = fwrite(String, sizeof(char), strlen(String), Fp); \ - if( i != strlen(String) * sizeof(char) ) { \ - goto error; \ - } \ + if(i != strlen(String) * sizeof(char)) goto error; \ } (void)0 - #define SNPRINTF(Buf, Sz, Str, Arg0, Arg1, Arg2) \ { \ const int i = snprintf(Buf, Sz, Str, Arg0, Arg1, Arg2); \ - if( i >= BUFSIZ ) { \ - goto error; \ - } \ + if( i >= BUFSIZ ) goto error; \ } (void)0 SNPRINTF(buf, BUFSIZ, "P3\n\n%i %i\n%i\n", width, height, 255); @@ -49,12 +44,10 @@ image_ppm_write const unsigned char* row = buffer + y * pitch; for(x = 0; x < width; ++x) { const unsigned char* pixel = row + x * Bpp; - SNPRINTF - (buf, BUFSIZ, - "%u %u %u\n", - pixel[0], - Bpp > 1 ? pixel[1] : pixel[0], - Bpp > 2 ? pixel[2] : pixel[0]); + SNPRINTF(buf, BUFSIZ, "%u %u %u\n", + pixel[0], + Bpp > 1 ? pixel[1] : pixel[0], + Bpp > 2 ? pixel[2] : pixel[0]); FWRITE(fp, buf); } FWRITE(fp, "\n"); @@ -67,6 +60,7 @@ exit: fclose(fp); return err; error: + err = -1; goto exit; }