Revision: 48445
          http://brlcad.svn.sourceforge.net/brlcad/?rev=48445&view=rev
Author:   n_reed
Date:     2012-01-11 22:05:47 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
always check returns from getc, CID 112, 115, 116

Modified Paths:
--------------
    brlcad/trunk/src/liborle/rle.c

Modified: brlcad/trunk/src/liborle/rle.c
===================================================================
--- brlcad/trunk/src/liborle/rle.c      2012-01-11 21:23:43 UTC (rev 48444)
+++ brlcad/trunk/src/liborle/rle.c      2012-01-11 22:05:47 UTC (rev 48445)
@@ -112,6 +112,15 @@
     RLEpixel *last;
 } runs[NSEG];          /* ptrs to non-background run segs */
 
+#define GETC_CHECKED(c, fp, err_ret) \
+{ \
+    int _c = getc(fp); \
+    if (_c == EOF) { \
+       return err_ret; \
+    } \
+    c = (char)_c; \
+}
+
 /* Global data.                                                                
*/
 int _bg_flag;
 int _bw_flag;
@@ -185,8 +194,8 @@
 
     p = (char *) &instruction;
 
-    *p++ = getc(fp);
-    *p++ = getc(fp);
+    GETC_CHECKED(*p++, fp, EOF);
+    GETC_CHECKED(*p++, fp, EOF);
     SWAB(*((short *)&instruction));
     if (feof(fp))
        return EOF;
@@ -202,18 +211,17 @@
 {
     static short long_data;
 
-    *opcode = getc(fp);
-    *datum = getc(fp);
+    GETC_CHECKED(*opcode, fp, EOF);
+    GETC_CHECKED(*datum, fp, EOF);
     if (*opcode & LONG) {
        register char *p = (char *) &long_data;
        *opcode &= ~LONG;
-       *p++ = getc(fp);
-       *p++ = getc(fp);
+       GETC_CHECKED(*p++, fp, EOF);
+       GETC_CHECKED(*p++, fp, EOF);
        SWAB(long_data);
        *datum = long_data;
     }
-    if (feof(fp))
-       return EOF;
+
     return 1;
 }
 
@@ -597,7 +605,7 @@
                PRNT_A1_DEBUG("Byte-Data", n);
                if (! _bw_flag) {
                    while (n-- > 0) {
-                       *pp = getc(fp);
+                       GETC_CHECKED(*pp, fp, -1);
                        pp += STRIDE;
                    }
                } else {
@@ -605,14 +613,17 @@
                    register unsigned char c;
                    while (n-- > 0) {
                        /* Implicit knowledge of sizeof(RLEpixel) */
-                       *pp++ = c = getc(fp);
+                       GETC_CHECKED(c, fp, -1);
                        *pp++ = c;
                        *pp++ = c;
+                       *pp++ = c;
                    }
                }
                if ((datum + 1) & 1) {
                    /* word align file ptr */
-                   (void) getc(fp);
+                   if (getc(fp) == EOF) {
+                       return -1;
+                   }
                }
                dirty_flag = 1;
                break;
@@ -620,8 +631,8 @@
                n = datum + 1;
                {
                    register char *p = (char *) &word;
-                   *p++ = getc(fp);
-                   *p++ = getc(fp);
+                   GETC_CHECKED(*p++, fp, -1);
+                   GETC_CHECKED(*p++, fp, -1);
                    SWAB(word);
                }
                PRNT_A2_DEBUG("Run-Data", (long)n,      word);

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


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to