[hackers] [farbfeld] Fix bugs in farbfeld(5)-example || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 5 Jan 2016 01:40:55 +0100 (CET)

commit ac1630a81790f5db946d7091e08b758714c8cd19
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Tue Jan 5 01:39:10 2016 +0100
Commit: FRIGN <dev_AT_frign.de>
CommitDate: Tue Jan 5 01:39:10 2016 +0100

    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.

diff --git a/farbfeld.5 b/farbfeld.5
index 8c8ec31..74bd02c 100644
--- a/farbfeld.5
+++ b/farbfeld.5
_AT_@ -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);
                 }
_AT_@ -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);
                 }
Received on Tue Jan 05 2016 - 01:40:55 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 05 2016 - 01:48:15 CET