commit d8501da4900ecd17a2eb9c83685e1c2eac7bfde6
parent 3c79ee8c9bad9e08e8965832d8d930ff11d40cd6
Author: sin <sin@2f30.org>
Date: Tue, 29 Jul 2014 12:44:02 +0100
Don't bother to cleanup in error cases
These tools are "one-shot", nobody cares about memory leaks while
the program is running.
Bring back -Os, no more false positives because there's no interaction
between gotos and setjmp/longjmp.
Diffstat:
3 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/config.mk b/config.mk
@@ -7,7 +7,7 @@ PREFIX = /usr/local
LIBS = -lpng
# flags
-CFLAGS = -std=c90 -ansi -pedantic -Wall -Wextra
+CFLAGS = -std=c90 -ansi -pedantic -Wall -Wextra -Os
LDFLAGS = -s ${LIBS}
# compiler and linker
diff --git a/if2png.c b/if2png.c
@@ -40,11 +40,11 @@ main(int argc, char *argv[])
/* header */
if (fread(hdr, 1, strlen(HEADER_FORMAT), stdin) != strlen(HEADER_FORMAT)) {
fprintf(stderr, "failed to read from stdin or input too short\n");
- goto err;
+ return EXIT_FAILURE;
}
if (memcmp("imagefile", hdr, 9)) {
fprintf(stderr, "invalid magic in header\n");
- goto err;
+ return EXIT_FAILURE;
}
width = ntohl((hdr[9] << 0) | (hdr[10] << 8) | (hdr[11] << 16) | (hdr[12] << 24));
height = ntohl((hdr[13] << 0) | (hdr[14] << 8) | (hdr[15] << 16) | (hdr[16] << 24));
@@ -55,7 +55,7 @@ main(int argc, char *argv[])
if (!png_struct_p || !png_info_p || setjmp(png_jmpbuf(png_struct_p))) {
fprintf(stderr, "failed to initialize libpng\n");
- goto err;
+ return EXIT_FAILURE;
}
png_init_io(png_struct_p, stdout);
png_set_IHDR(png_struct_p, png_info_p, width, height, 8, PNG_COLOR_TYPE_RGB_ALPHA,
@@ -67,13 +67,13 @@ main(int argc, char *argv[])
png_row = malloc(png_row_len);
if (!png_row) {
fprintf(stderr, "failed to allocate row-buffer\n");
- goto err;
+ return EXIT_FAILURE;
}
for (i = 0; i < height; ++i) {
if (fread(png_row, 1, png_row_len, stdin) != png_row_len) {
fprintf(stderr, "unexpected EOF or row-skew at %lu\n", (unsigned long)i);
- goto err;
+ return EXIT_FAILURE;
}
png_write_row(png_struct_p, png_row);
}
@@ -84,9 +84,4 @@ main(int argc, char *argv[])
png_destroy_write_struct(&png_struct_p, NULL);
free(png_row);
return EXIT_SUCCESS;
-err:
- png_free_data(png_struct_p, png_info_p, PNG_FREE_ALL, -1);
- png_destroy_write_struct(&png_struct_p, NULL);
- free(png_row);
- return EXIT_FAILURE;
}
diff --git a/png2if.c b/png2if.c
@@ -43,7 +43,7 @@ main(int argc, char *argv[])
if (!png_struct_p || !png_info_p || setjmp(png_jmpbuf(png_struct_p))) {
fprintf(stderr, "failed to initialize libpng");
- goto err;
+ return EXIT_FAILURE;
}
png_init_io(png_struct_p, stdin);
png_set_add_alpha(png_struct_p, 255, PNG_FILLER_AFTER);
@@ -66,14 +66,11 @@ main(int argc, char *argv[])
for (i = 0; i < height; i++) {
if (fwrite(png_row_p[i], 1, png_row_len, stdout) != png_row_len) {
fprintf(stderr, "fwrite() failed\n");
- goto err;
+ return EXIT_FAILURE;
}
}
/* clean up */
png_destroy_read_struct(&png_struct_p, &png_info_p, NULL);
return EXIT_SUCCESS;
-err:
- png_destroy_read_struct(&png_struct_p, &png_info_p, NULL);
- return EXIT_FAILURE;
}