summaryrefslogtreecommitdiff
path: root/ff2png.c
diff options
context:
space:
mode:
authorFRIGN <dev@frign.de>2016-03-04 12:23:04 +0100
committerFRIGN <dev@frign.de>2016-03-04 12:23:04 +0100
commit3122c071397b4db9c9122072c56bd31c02085ca7 (patch)
treeb6551b46d6e29479306cb2532cdf2dd5e5cfd6d8 /ff2png.c
parent14df2f24dfedf9d12dcec02d57c596a34be0f197 (diff)
Use uint32-array to store the header
this goes around the undefined behaviour imposed by using (*(uint32_t *)(hdr + 4n))
Diffstat (limited to 'ff2png.c')
-rw-r--r--ff2png.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/ff2png.c b/ff2png.c
index 52bdc58..bf210fb 100644
--- a/ff2png.c
+++ b/ff2png.c
@@ -9,8 +9,6 @@
#include <png.h>
-#define HDR "farbfeld########"
-
static char *argv0;
void
@@ -26,9 +24,8 @@ main(int argc, char *argv[])
png_structp pngs;
png_infop pngi;
size_t rowlen;
- uint32_t width, height, i;
+ uint32_t hdr[4], width, height, i;
uint16_t *row;
- uint8_t hdr[16];
argv0 = argv[0], argc--, argv++;
@@ -38,15 +35,15 @@ main(int argc, char *argv[])
}
/* header */
- if (fread(hdr, 1, sizeof(HDR) - 1, stdin) != sizeof(HDR) - 1) {
+ if (fread(hdr, sizeof(*hdr), 4, stdin) != 4) {
goto readerr;
}
if (memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) {
fprintf(stderr, "%s: invalid magic value\n", argv0);
return 1;
}
- width = ntohl(*((uint32_t *)(hdr + 8)));
- height = ntohl(*((uint32_t *)(hdr + 12)));
+ width = ntohl(hdr[2]);
+ height = ntohl(hdr[3]);
/* load png */
pngs = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, pngerr,