diff options
author | FRIGN <dev@frign.de> | 2016-01-05 01:39:10 +0100 |
---|---|---|
committer | FRIGN <dev@frign.de> | 2016-01-05 01:39:10 +0100 |
commit | ac1630a81790f5db946d7091e08b758714c8cd19 (patch) | |
tree | e93d358e9fda5e01c4b9269f1b65c912ab94de6f /farbfeld.5 | |
parent | 86495f8058518f7064f2ddda92314aa42163b4c0 (diff) |
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.
Diffstat (limited to 'farbfeld.5')
-rw-r--r-- | farbfeld.5 | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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); } |