summaryrefslogtreecommitdiff
path: root/farbfeld.5
diff options
context:
space:
mode:
authorFRIGN <dev@frign.de>2016-01-05 01:39:10 +0100
committerFRIGN <dev@frign.de>2016-01-05 01:39:10 +0100
commitac1630a81790f5db946d7091e08b758714c8cd19 (patch)
treee93d358e9fda5e01c4b9269f1b65c912ab94de6f /farbfeld.5
parent86495f8058518f7064f2ddda92314aa42163b4c0 (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.59
1 files 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);
}