about summary refs log tree commit diff
path: root/converter
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-06-03 21:16:48 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-06-03 21:16:48 +0000
commit800e0d9b35536d190cf2054d485ad3c76989e4a1 (patch)
tree0a82d3309f372d5605824a489a1880ba10c24d7f /converter
parent8e1d5ee4ea4fcb2b3148fe872e0f7998f69683f4 (diff)
downloadnetpbm-mirror-800e0d9b35536d190cf2054d485ad3c76989e4a1.tar.gz
netpbm-mirror-800e0d9b35536d190cf2054d485ad3c76989e4a1.tar.xz
netpbm-mirror-800e0d9b35536d190cf2054d485ad3c76989e4a1.zip
Fix bugs from previous commit
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3829 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter')
-rw-r--r--converter/other/cameratopam/camera.c4
-rw-r--r--converter/other/cameratopam/stdio_nofail.c41
-rw-r--r--converter/other/cameratopam/stdio_nofail.h6
3 files changed, 42 insertions, 9 deletions
diff --git a/converter/other/cameratopam/camera.c b/converter/other/cameratopam/camera.c
index 3b29d1ac..4610462c 100644
--- a/converter/other/cameratopam/camera.c
+++ b/converter/other/cameratopam/camera.c
@@ -450,7 +450,7 @@ rollei_load_raw(Image const image) {
   unsigned iten=0, isix, i, buffer=0, row, col, todo[16];
 
   isix = raw_width * raw_height * 5 / 8;
-  while (fread_nofail (pixel, 1, 10, ifp) == 10) {
+  while (fread_or_eof_nofail (pixel, 1, 10, ifp) == 10) {
     for (i=0; i < 10; i+=2) {
       todo[i]   = iten++;
       todo[i+1] = pixel[i] << 8 | pixel[i+1];
@@ -784,7 +784,7 @@ fill_input_buffer (j_decompress_ptr cinfo)
   static char jpeg_buffer[4096];
   size_t nbytes;
 
-  nbytes = fread_nofail (jpeg_buffer, 1, 4096, ifp);
+  nbytes = fread_or_eof_nofail (jpeg_buffer, 1, 4096, ifp);
   swab (jpeg_buffer, jpeg_buffer, nbytes);
   cinfo->src->next_input_byte = jpeg_buffer;
   cinfo->src->bytes_in_buffer = nbytes;
diff --git a/converter/other/cameratopam/stdio_nofail.c b/converter/other/cameratopam/stdio_nofail.c
index 683d068a..97a8796d 100644
--- a/converter/other/cameratopam/stdio_nofail.c
+++ b/converter/other/cameratopam/stdio_nofail.c
@@ -9,6 +9,26 @@
 
 
 size_t
+fread_or_eof_nofail(void * const ptr,
+                    size_t const size,
+                    size_t const nmemb,
+                    FILE * const streamP) {
+
+    size_t rc;
+
+    rc = fread(ptr, size, nmemb, streamP);
+
+    if (rc < nmemb) {
+        if (!feof(streamP))
+            pm_error("File read failed.  Errno=%d (%s)",
+                     errno, strerror(errno));
+    }
+    return rc;
+}
+
+
+
+void
 fread_nofail(void * const ptr,
              size_t const size,
              size_t const nmemb,
@@ -18,10 +38,13 @@ fread_nofail(void * const ptr,
 
     rc = fread(ptr, size, nmemb, streamP);
 
-    if (rc < 0)
-        pm_error("File read failed.  Errno=%d (%s)", errno, strerror(errno));
-
-    return rc;
+    if (rc < nmemb) {
+        if (feof(streamP))
+            pm_error("File read failed.  Premature end of file");
+        else
+            pm_error("File read failed.  Errno=%d (%s)",
+                     errno, strerror(errno));
+    }
 }
 
 
@@ -33,9 +56,13 @@ fgetc_nofail(FILE * streamP) {
 
     rc = fgetc(streamP);
 
-    if (rc < 0)
-        pm_error("File read failed.  Errno=%d (%s)", errno, strerror(errno));
-
+    if (rc == EOF) {
+        if (feof(streamP))
+            pm_error("File read failed.  Premature end of file");
+        else
+            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 f220b4ac..8f45b537 100644
--- a/converter/other/cameratopam/stdio_nofail.h
+++ b/converter/other/cameratopam/stdio_nofail.h
@@ -1,6 +1,12 @@
 #include <stdio.h>
 
 size_t
+fread_or_eof_nofail(void * const ptr,
+                    size_t const size,
+                    size_t const nmemb,
+                    FILE * const streamP);
+
+void
 fread_nofail(void * const ptr,
              size_t const size,
              size_t const nmemb,