5f6963
diff -up jbigkit-2.1/pbmtools/pbmtojbg85.c.warnings jbigkit-2.1/pbmtools/pbmtojbg85.c
5f6963
--- jbigkit-2.1/pbmtools/pbmtojbg85.c.warnings	2008-08-26 00:26:39.000000000 +0200
5f6963
+++ jbigkit-2.1/pbmtools/pbmtojbg85.c	2012-07-17 16:24:56.741332942 +0200
5f6963
@@ -72,9 +72,12 @@ static unsigned long getint(FILE *f)
5f6963
       while ((c = getc(f)) != EOF && !(c == 13 || c == 10)) ;
5f6963
   if (c != EOF) {
5f6963
     ungetc(c, f);
5f6963
-    fscanf(f, "%lu", &i);
5f6963
+    if (fscanf(f, "%lu", &i) != 1) {
5f6963
+      /* should never fail, since c must be a digit */
5f6963
+      fprintf(stderr, "Unexpected failure reading digit '%c'\n", c);
5f6963
+      exit(1);
5f6963
+    }
5f6963
   }
5f6963
-
5f6963
   return i;
5f6963
 }
5f6963
 
5f6963
@@ -239,7 +242,9 @@ int main (int argc, char **argv)
5f6963
       break;
5f6963
     case '4':
5f6963
       /* PBM raw binary format */
5f6963
-      fread(next_line, bpl, 1, fin);
5f6963
+      if (fread(next_line, bpl, 1, fin) != 1) {
5f6963
+	/* silence compiler warnings; ferror/feof checked below */
5f6963
+      }
5f6963
       break;
5f6963
     default:
5f6963
       fprintf(stderr, "Unsupported PBM type P%c!\n", type);
5f6963
diff -up jbigkit-2.1/pbmtools/pbmtojbg.c.warnings jbigkit-2.1/pbmtools/pbmtojbg.c
5f6963
--- jbigkit-2.1/pbmtools/pbmtojbg.c.warnings	2008-07-16 22:59:41.000000000 +0200
5f6963
+++ jbigkit-2.1/pbmtools/pbmtojbg.c	2012-07-17 16:23:46.584285686 +0200
5f6963
@@ -88,7 +88,11 @@ static unsigned long getint(FILE *f)
5f6963
       while ((c = getc(f)) != EOF && !(c == 13 || c == 10)) ;
5f6963
   if (c != EOF) {
5f6963
     ungetc(c, f);
5f6963
-    fscanf(f, "%lu", &i);
5f6963
+    if (fscanf(f, "%lu", &i) != 1) {
5f6963
+      /* should never fail, since c must be a digit */
5f6963
+      fprintf(stderr, "Unexpected failure reading digit '%c'\n", c);
5f6963
+      exit(1);
5f6963
+    }
5f6963
   }
5f6963
 
5f6963
   return i;
5f6963
@@ -302,7 +306,9 @@ int main (int argc, char **argv)
5f6963
     break;
5f6963
   case '4':
5f6963
     /* PBM raw binary format */
5f6963
-    fread(bitmap[0], bitmap_size, 1, fin);
5f6963
+    if (fread(bitmap[0], bitmap_size, 1, fin) != 1) {
5f6963
+      /* silence compiler warnings; ferror/feof checked below */
5f6963
+    }
5f6963
     break;
5f6963
   case '2':
5f6963
   case '5':
5f6963
@@ -314,8 +320,18 @@ int main (int argc, char **argv)
5f6963
 	for (j = 0; j < bpp; j++)
5f6963
 	  image[x * bpp + (bpp - 1) - j] = v >> (j * 8);
5f6963
       }
5f6963
-    } else
5f6963
-      fread(image, width * height, bpp, fin);
5f6963
+    } else {
5f6963
+      if (fread(image, width * height, bpp, fin) != (size_t) bpp) {
5f6963
+	if (ferror(fin)) {
5f6963
+	  fprintf(stderr, "Problem while reading input file '%s", fnin);
5f6963
+	  perror("'");
5f6963
+	  exit(1);
5f6963
+	} else {
5f6963
+	  fprintf(stderr, "Unexpected end of input file '%s'!\n", fnin);
5f6963
+	  exit(1);
5f6963
+	}
5f6963
+      }
5f6963
+    }
5f6963
     jbg_split_planes(width, height, planes, encode_planes, image, bitmap,
5f6963
 		     use_graycode);
5f6963
     free(image);