From ac1630a81790f5db946d7091e08b758714c8cd19 Mon Sep 17 00:00:00 2001 From: FRIGN Date: Tue, 5 Jan 2016 01:39:10 +0100 Subject: Fix bugs in farbfeld(5)-example 1) We forgot to write the header out again (no changes, but else the format would have obviously been broken) 2) The order of 'size' and 'count' was wrong in the fread- and fwrite- calls inside the loops, and the checks were failing. now this is fixed. --- farbfeld.5 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/farbfeld.5 b/farbfeld.5 index 8c8ec31..74bd02c 100644 --- a/farbfeld.5 +++ b/farbfeld.5 @@ -72,9 +72,14 @@ if (memcmp("farbfeld", hdr, strlen("farbfeld"))) { width = ntohl(*((uint32_t *)(hdr + 8))); height = ntohl(*((uint32_t *)(hdr + 12))); +if (fwrite(hdr, 1, sizeof(hdr), outfile) != sizeof(hdr)) { + fprintf(stderr, "write error\\n"); + exit(1); +} + for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { - if (fread(rgba, 4, sizeof(uint16_t), infile) != 4) { + if (fread(rgba, sizeof(uint16_t), 4, infile) != 4) { fprintf(stderr, "unexpected EOF\\n"); exit(1); } @@ -90,7 +95,7 @@ for (i = 0; i < height; i++) { for (k = 0; k < 4; k++) { rgba[k] = htons(rgba[k]); } - if (fwrite(rgba, 4, sizeof(uint16_t), outfile) != 4) { + if (fwrite(rgba, sizeof(uint16_t), 4, outfile) != 4) { fprintf(stderr, "write error\\n"); exit(1); } -- cgit v1.2.3