Revision: 41568
          http://brlcad.svn.sourceforge.net/brlcad/?rev=41568&view=rev
Author:   brlcad
Date:     2010-12-08 22:54:51 +0000 (Wed, 08 Dec 2010)

Log Message:
-----------
more checking of return values for fwrite/fread/scanf that were queued up on 
release tagging.

Modified Paths:
--------------
    brlcad/trunk/src/util/bwhisteq.c
    brlcad/trunk/src/util/pix3filter.c
    brlcad/trunk/src/util/pixmorph.c
    brlcad/trunk/src/util/rle-pix.c
    brlcad/trunk/src/util/wavelet.c

Modified: brlcad/trunk/src/util/bwhisteq.c
===================================================================
--- brlcad/trunk/src/util/bwhisteq.c    2010-12-08 22:17:10 UTC (rev 41567)
+++ brlcad/trunk/src/util/bwhisteq.c    2010-12-08 22:54:51 UTC (rev 41568)
@@ -57,6 +57,7 @@
     int left[256], right[256];
     double hint, havg;
     long r;
+    size_t ret;
 
     if (argc > 1 && strcmp(argv[1], "-v") == 0) {
        verbose++;
@@ -119,7 +120,11 @@
 #endif /* Not METHOD2 */
            }
        }
-       fwrite(obuf, 1, n, stdout);
+       ret = fwrite(obuf, 1, n, stdout);
+       if (ret == 0) {
+           perror("fwrite");
+           break;
+       }
     }
     return 0;
 }

Modified: brlcad/trunk/src/util/pix3filter.c
===================================================================
--- brlcad/trunk/src/util/pix3filter.c  2010-12-08 22:17:10 UTC (rev 41567)
+++ brlcad/trunk/src/util/pix3filter.c  2010-12-08 22:54:51 UTC (rev 41568)
@@ -215,6 +215,7 @@
 int
 main(int argc, char **argv)
 {
+    size_t ret;
     int x, y, color;
     int value, r1, r2, r3, r4, r5, r6, r7, r8, r9;
     int max, min;
@@ -246,25 +247,40 @@
     bottomnew = l31;
     middlenew = l32;
     topnew    = l33;
+
 /*
  * Read in the bottom and middle rows of the old picture.
  */
-    fread(bottomold, sizeof(char), 3*width, oldfp);
-    fread(middleold, sizeof(char), 3*width, oldfp);
-/*
- * Read in the bottom and middle rows of the current picture.
- */
-    fread(bottomcur, sizeof(char), 3*width, curfp);
-    fread(middlecur, sizeof(char), 3*width, curfp);
-/*
- * Read in the bottom and middle rows of the new picture.
- */
-    fread(bottomnew, sizeof(char), 3*width, newfp);
-    fread(middlenew, sizeof(char), 3*width, newfp);
-/*
- * Write out the bottome row.
- */
-    fwrite(bottomcur, sizeof(char), 3*width, stdout);
+    ret = fread(bottomold, sizeof(char), 3*width, oldfp);
+    if (ret == 0)
+       perror("fread");
+    ret = fread(middleold, sizeof(char), 3*width, oldfp);
+    if (ret == 0)
+       perror("fread");
+    /*
+     * Read in the bottom and middle rows of the current picture.
+     */
+    ret = fread(bottomcur, sizeof(char), 3*width, curfp);
+    if (ret == 0)
+       perror("fread");
+    ret = fread(middlecur, sizeof(char), 3*width, curfp);
+    if (ret == 0)
+       perror("fread");
+    /*
+     * Read in the bottom and middle rows of the new picture.
+     */
+    ret = fread(bottomnew, sizeof(char), 3*width, newfp);
+    if (ret == 0)
+       perror("fread");
+    ret = fread(middlenew, sizeof(char), 3*width, newfp);
+    if (ret == 0)
+       perror("fread");
+    /*
+     * Write out the bottome row.
+     */
+    ret = fwrite(bottomcur, sizeof(char), 3*width, stdout);
+    if (ret == 0)
+       perror("fwrite");
 
     if (verbose) {
        for (x = 0; x < 29; x++)
@@ -276,9 +292,15 @@
 
     for (y = 1; y < height-1; y++) {
        /* read in top lines */
-       fread(topold, sizeof(char), 3*width, oldfp);
-       fread(topcur, sizeof(char), 3*width, curfp);
-       fread(topnew, sizeof(char), 3*width, newfp);
+       ret = fread(topold, sizeof(char), 3*width, oldfp);
+       if (ret == 0)
+           perror("fread");
+       ret = fread(topcur, sizeof(char), 3*width, curfp);
+       if (ret == 0)
+           perror("fread");
+       ret = fread(topnew, sizeof(char), 3*width, newfp);
+       if (ret == 0)
+           perror("fread");
 
        for (color = 0; color < 3; color++) {
            obuf[0+color] = middlecur[0+color];
@@ -328,7 +350,10 @@
            }
            obuf[3*(width-1)+color] = middlecur[3*(width-1)+color];
        }
-       fwrite(obuf, sizeof(char), 3*width, stdout);
+       ret = fwrite(obuf, sizeof(char), 3*width, stdout);
+       if (ret == 0)
+           perror("fwrite");
+
        /* Adjust row pointers */
        temp = bottomold;
        bottomold = middleold;
@@ -347,7 +372,9 @@
 
     }
     /* write out last line untouched */
-    fwrite(topcur, sizeof(char), 3*width, stdout);
+    ret = fwrite(topcur, sizeof(char), 3*width, stdout);
+    if (ret == 0)
+       perror("fwrite");
 
     /* Give advise on scaling factors */
     if (verbose)

Modified: brlcad/trunk/src/util/pixmorph.c
===================================================================
--- brlcad/trunk/src/util/pixmorph.c    2010-12-08 22:17:10 UTC (rev 41567)
+++ brlcad/trunk/src/util/pixmorph.c    2010-12-08 22:54:51 UTC (rev 41568)
@@ -282,8 +282,7 @@
     for (i = 0; i < numlines; i++, lines++) {
        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf %lf %lf ",
                   &x_1, &y_1, &x_2, &y_2, &x_3, &y_3, &x_4, &y_4) < 4) {
-           fprintf(stderr, "pixmorph: lines_read: failure\n");
-           bu_exit (1, NULL);
+           bu_exit(1, "pixmorph: lines_read: failure\n");
        }
 
        if ((fabs(x_1-x_2) < EPSILON && fabs(y_1-y_2) < EPSILON) ||
@@ -338,8 +337,7 @@
 lines_headerinfo(FILE *fp, double *ap, double *bp, double *pp, long int *np)
 {
     if (fscanf(fp, "%lf %lf %lf %ld ", ap, bp, pp, np) < 4) {
-       fprintf(stderr, "pixmorph: cannot read header info in lines file\n");
-       bu_exit (1, NULL);
+       bu_exit(1, "pixmorph: cannot read header info in lines file\n");
     }
 }
 

Modified: brlcad/trunk/src/util/rle-pix.c
===================================================================
--- brlcad/trunk/src/util/rle-pix.c     2010-12-08 22:17:10 UTC (rev 41567)
+++ brlcad/trunk/src/util/rle-pix.c     2010-12-08 22:54:51 UTC (rev 41568)
@@ -161,6 +161,7 @@
     int screen_xbase;          /* screen X of l.h.s. of rectangle */
     int screen_xlen;           /* clipped len of rectangle */
     int ncolors;
+    size_t ret;
 
     infp = stdin;
     outfp = stdout;
@@ -298,8 +299,11 @@
        rle_getrow(&rle_dflt_hdr, rows);
 
     /* Background-fill any lines above 0, below ymin */
-    for (i=0; i < rle_dflt_hdr.ymin; i++)
-       fwrite((char *)bg_buf, sizeof(RGBpixel), (size_t)screen_xlen, outfp);
+    for (i=0; i < rle_dflt_hdr.ymin; i++) {
+       ret = fwrite((char *)bg_buf, sizeof(RGBpixel), (size_t)screen_xlen, 
outfp);
+       if (ret == 0)
+           perror("fwrite");
+    }
 
     for (; i <= rle_dflt_hdr.ymax; i++) {
        unsigned char *pp = (unsigned char *)scan_buf;
@@ -324,13 +328,18 @@
                *pp++ = cmap.cm_blue[*bp++]>>8;
            }
        }
-       fwrite((char *)scan_buf, sizeof(RGBpixel), (size_t)screen_xlen, outfp);
+       ret = fwrite((char *)scan_buf, sizeof(RGBpixel), (size_t)screen_xlen, 
outfp);
+       if (ret == 0)
+           perror("fwrite");
     }
 
 
     /* Background-fill any lines above ymax, below screen_height */
-    for (; i < screen_height; i++)
-       fwrite((char *)bg_buf, sizeof(RGBpixel), (size_t)screen_xlen, outfp);
+    for (; i < screen_height; i++) {
+       ret = fwrite((char *)bg_buf, sizeof(RGBpixel), (size_t)screen_xlen, 
outfp);
+       if (ret == 0)
+           perror("fwrite");
+    }
  done:
 
     for (i=0; i < ncolors; i++)

Modified: brlcad/trunk/src/util/wavelet.c
===================================================================
--- brlcad/trunk/src/util/wavelet.c     2010-12-08 22:17:10 UTC (rev 41567)
+++ brlcad/trunk/src/util/wavelet.c     2010-12-08 22:54:51 UTC (rev 41568)
@@ -85,13 +85,11 @@
 {
     if (s) (void)fputs(s, stderr);
 
-    (void) fprintf(stderr,
-                  "Usage:\n\
+    bu_exit(1,
+           "Usage:\n\
        %s {-d | -r} [-2] [-t datatype] [-# channels]\n\
        [-w width] [-n scanlines] [-s number_of_samples]\n\
-       < datastream > wavelets\n",
-                  progname);
-    bu_exit (1, NULL);
+       < datastream > wavelets\n", progname);
 }
 
 
@@ -168,6 +166,7 @@
 void
 wlt_decompose_1d(void)
 {
+    size_t ret;
     genptr_t buf, tbuf;
     unsigned long int i, n;
     unsigned long int sample_size;     /* size of data type x #values/sample */
@@ -188,10 +187,7 @@
 
        n = fread(buf, sample_size, width, stdin);
        if (n != width) {
-           fprintf(stderr,
-                   "read failed line %lu got %lu not %lu\n",
-                   i, n, width);
-           bu_exit (-1, NULL);
+           bu_exit(1, "read failed line %lu got %lu not %lu\n", i, n, width);
        }
 
        switch (value_type) {
@@ -221,7 +217,11 @@
                break;
        }
 
-       fwrite(buf, sample_size, width, stdout);
+       ret = fwrite(buf, sample_size, width, stdout);
+       if (ret == 0) {
+           perror("fwrite");
+           break;
+       }
     }
 }
 
@@ -229,6 +229,7 @@
 void
 wlt_decompose_2d(void)
 {
+    size_t ret;
     genptr_t buf, tbuf;
     unsigned long int sample_size;
     unsigned long int scanline_size;
@@ -246,13 +247,11 @@
 
     if (width != height) {
        fprintf(stderr, "Two dimensional decomposition requires square 
image\n");
-       fprintf(stderr, "%lu x %lu image specified\n", width, height);
-       bu_exit (-1, NULL);
+       bu_exit(1, "%lu x %lu image specified\n", width, height);
     }
 
     if (fread(buf, scanline_size, height, stdin) != height) {
-       fprintf(stderr, "read error getting %lux%lu bytes\n", scanline_size, 
height);
-       bu_exit (-1, NULL);
+       bu_exit(1, "read error getting %lux%lu bytes\n", scanline_size, height);
     }
 
     switch (value_type) {
@@ -281,13 +280,17 @@
                                          channels, limit);
            break;
     }
-    fwrite(buf, scanline_size, width, stdout);
+    ret = fwrite(buf, scanline_size, width, stdout);
+    if (ret == 0) {
+       perror("fwrite");
+    }
 }
 
 
 void
 wlt_reconstruct_1d(void)
 {
+    size_t ret;
     genptr_t buf, tbuf;
     unsigned long int i, n;
     unsigned long int sample_size;     /* size of data type x #values/sample */
@@ -309,10 +312,7 @@
 
        n = fread(buf, sample_size, width, stdin);
        if (n != width) {
-           fprintf(stderr,
-                   "read failed line %lu got %lu not %lu\n",
-                   i, n, width);
-           bu_exit (-1, NULL);
+           bu_exit(-1, "read failed line %lu got %lu not %lu\n", i, n, width);
        }
 
        switch (value_type) {
@@ -342,7 +342,11 @@
                break;
        }
 
-       fwrite(buf, sample_size, width, stdout);
+       ret = fwrite(buf, sample_size, width, stdout);
+       if (ret == 0) {
+           perror("fwrite");
+           break;
+       }
     }
 }
 
@@ -350,6 +354,7 @@
 void
 wlt_reconstruct_2d(void)
 {
+    size_t ret;
     genptr_t buf, tbuf;
     unsigned long int sample_size;
     unsigned long int scanline_size;
@@ -366,13 +371,11 @@
 
     if (width != height) {
        fprintf(stderr, "Two dimensional decomposition requires square 
image\n");
-       fprintf(stderr, "%lu x %lu image specified\n", width, height);
-       bu_exit (-1, NULL);
+       bu_exit(1, "%lu x %lu image specified\n", width, height);
     }
 
     if (fread(buf, scanline_size, height, stdin) != height) {
-       fprintf(stderr, "read error getting %lux%lu bytes\n", scanline_size, 
height);
-       bu_exit (-1, NULL);
+       bu_exit(1, "read error getting %lux%lu bytes\n", scanline_size, height);
     }
 
     switch (value_type) {
@@ -401,7 +404,10 @@
                                            channels, avg_size, limit);
            break;
     }
-    fwrite(buf, scanline_size, width, stdout);
+    ret = fwrite(buf, scanline_size, width, stdout);
+    if (ret == 0) {
+       perror("fwrite");
+    }
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF Dev2Dev email is sponsored by:

WikiLeaks The End of the Free Internet
http://p.sf.net/sfu/therealnews-com
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to