about summary refs log tree commit diff
path: root/converter
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-05-30 03:58:40 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-05-30 03:58:40 +0000
commit3a89edb7a07c96e24d4e233a7c81df72a6d5fa88 (patch)
tree6fbda0071b78a3db57c882ea0ebccf380d630385 /converter
parentaa17eb4f8424ea6548af66c7dbf819aecd399d57 (diff)
downloadnetpbm-mirror-3a89edb7a07c96e24d4e233a7c81df72a6d5fa88.tar.gz
netpbm-mirror-3a89edb7a07c96e24d4e233a7c81df72a6d5fa88.tar.xz
netpbm-mirror-3a89edb7a07c96e24d4e233a7c81df72a6d5fa88.zip
Handle failed I/O
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3823 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter')
-rw-r--r--converter/other/cameratopam/camera.c10
-rw-r--r--converter/other/cameratopam/cameratopam.c4
-rw-r--r--converter/other/cameratopam/stdio_nofail.c20
-rw-r--r--converter/other/cameratopam/stdio_nofail.h5
4 files changed, 31 insertions, 8 deletions
diff --git a/converter/other/cameratopam/camera.c b/converter/other/cameratopam/camera.c
index 261196b3..3b29d1ac 100644
--- a/converter/other/cameratopam/camera.c
+++ b/converter/other/cameratopam/camera.c
@@ -1276,7 +1276,7 @@ parse_rollei(FILE * const ifp)
 
   fseek_nofail (ifp, 0, SEEK_SET);
   do {
-    fgets (line, 128, ifp);
+    fgets_nofail (line, 128, ifp);
     if ((val = strchr(line,'=')))
       *val++ = 0;
     else
@@ -1581,10 +1581,10 @@ parse_tiff_ifd(FILE * const ifp, int base, int level)
     kodak_data_compression = get2(ifp);
     break;
       case 0x10f:           /* Make */
-    fgets (make, 64, ifp);
+    fgets_nofail (make, 64, ifp);
     break;
       case 0x110:           /* Model */
-    fgets (model, 64, ifp);
+    fgets_nofail (model, 64, ifp);
     break;
       case 0x111:           /* StripOffset */
     data_offset = get4(ifp);
@@ -1596,7 +1596,7 @@ parse_tiff_ifd(FILE * const ifp, int base, int level)
     tiff_samples = get2(ifp);
     break;
       case 0x131:           /* Software tag */
-    fgets (software, 64, ifp);
+    fgets_nofail (software, 64, ifp);
     if (!strncmp(software,"Adobe",5))
       make[0] = 0;
     break;
@@ -1622,7 +1622,7 @@ parse_tiff_ifd(FILE * const ifp, int base, int level)
     }
     break;
       case 33405:           /* Model2 */
-    fgets (model2, 64, ifp);
+    fgets_nofail (model2, 64, ifp);
     break;
       case 33422:           /* CFAPattern */
     if ((plen=len) > 16) plen = 16;
diff --git a/converter/other/cameratopam/cameratopam.c b/converter/other/cameratopam/cameratopam.c
index 78eb6854..d8936f30 100644
--- a/converter/other/cameratopam/cameratopam.c
+++ b/converter/other/cameratopam/cameratopam.c
@@ -23,7 +23,6 @@
 #include <limits.h>
 #include <math.h>
 #include <time.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -47,6 +46,7 @@
 #include "bayer.h"
 #include "foveon.h"
 #include "dng.h"
+#include "stdio_nofail.h"
 
 /*
    All global variables are defined here, and all functions that
@@ -233,7 +233,7 @@ fixBadPixels(Image const image) {
         }
         free (fname);
         if (fp) {
-            while (fgets (line, 128, fp)) {
+            while (fgets_nofail (line, 128, fp)) {
                 char * cp;
                 cp = strchr (line, '#');
                 if (cp) *cp = 0;
diff --git a/converter/other/cameratopam/stdio_nofail.c b/converter/other/cameratopam/stdio_nofail.c
index 0ccfc5b4..683d068a 100644
--- a/converter/other/cameratopam/stdio_nofail.c
+++ b/converter/other/cameratopam/stdio_nofail.c
@@ -51,7 +51,7 @@ fseek_nofail(FILE * const streamP,
     rc = fseek(streamP, offset, whence);
 
     if (rc < 0)
-        pm_error("File read failed.  Errno=%d (%s)", errno, strerror(errno));
+        pm_error("File seek failed.  Errno=%d (%s)", errno, strerror(errno));
 
     return rc;
 }
@@ -66,6 +66,24 @@ ftell_nofail(FILE * const streamP) {
     rc = ftell(streamP);
 
     if (rc < 0)
+        pm_error("File position query failed.  Errno=%d (%s)",
+                 errno, strerror(errno));
+
+    return rc;
+}
+
+
+
+char *
+fgets_nofail(char * const s,
+             int    const size,
+             FILE * const streamP) {
+
+    char * rc;
+
+    rc = fgets(s, size, streamP);
+
+    if (ferror(streamP))
         pm_error("File read failed.  Errno=%d (%s)", errno, strerror(errno));
 
     return rc;
diff --git a/converter/other/cameratopam/stdio_nofail.h b/converter/other/cameratopam/stdio_nofail.h
index 9d6fcea5..f220b4ac 100644
--- a/converter/other/cameratopam/stdio_nofail.h
+++ b/converter/other/cameratopam/stdio_nofail.h
@@ -16,3 +16,8 @@ fseek_nofail(FILE * const streamP,
 
 long
 ftell_nofail(FILE * const streamP);
+
+char *
+fgets_nofail(char * const s,
+             int    const size,
+             FILE * const streamP);