]> git.imager.perl.org - imager.git/blobdiff - pnm.c
work around compilation problem reported in
[imager.git] / pnm.c
diff --git a/pnm.c b/pnm.c
index 148b887ba7df4731f8bdd543a2050fe5234ab64a..e5d3050411c63c19bf8e7c093dbd8d04e5284aa4 100644 (file)
--- a/pnm.c
+++ b/pnm.c
@@ -1,6 +1,7 @@
-#include "image.h"
+#include "imager.h"
 #include "log.h"
 #include "iolayer.h"
+#include "imageri.h"
 
 #include <stdlib.h>
 #include <errno.h>
@@ -97,7 +98,7 @@ gnext(mbuf *mb) {
 
 
 /*
-=item gnext(mbuf *mb)
+=item gpeek(mbuf *mb)
 
 Fetches a character but does NOT advance.  Returns a pointer to
 the byte or NULL on failure (internal).
@@ -153,7 +154,7 @@ skip_spaces(mbuf *mb) {
 
 
 /*
-=item skip_spaces(mb)
+=item skip_comment(mb)
 
 Advances in stream over whitespace and a comment if one is found. (internal)
 
@@ -236,24 +237,8 @@ i_readpnm_wiol(io_glue *ig, int length) {
 
   i_clear_error();
 
-  /*  char *pp; */
-
   mm_log((1,"i_readpnm(ig %p, length %d)\n", ig, length));
 
-  /*
-  pp = mymalloc(20);
-  
-  pp[-1]= 'c';
-  pp[-2]= 'c';
-  
-  bndcheck_all();
-
-  myfree(pp);
-
-  mm_log((1, "Hack is exiting\n"));
-
-*/
-  
   io_glue_commit_types(ig);
   init_buf(&buf, ig);
 
@@ -359,6 +344,11 @@ i_readpnm_wiol(io_glue *ig, int length) {
   channels = (type == 3 || type == 6) ? 3:1;
   pcount = width*height*channels;
 
+  if (!i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))) {
+    mm_log((1, "i_readpnm: image size exceeds limits\n"));
+    return NULL;
+  }
+
   mm_log((1, "i_readpnm: (%d x %d), channels = %d, maxval = %d\n", width, height, channels, maxval));
   
   im = i_img_empty_ch(NULL, width, height, channels);
@@ -425,7 +415,6 @@ undef_int
 i_writeppm_wiol(i_img *im, io_glue *ig) {
   char header[255];
   int rc;
-  writep write_func;
 
   mm_log((1,"i_writeppm(im %p, ig %p)\n", im, ig));
   i_clear_error();
@@ -450,8 +439,6 @@ i_writeppm_wiol(i_img *im, io_glue *ig) {
       unsigned char *data = mymalloc(3 * im->xsize);
       if (data != NULL) {
         int y = 0;
-        int x, ch;
-        unsigned char *p;
         static int rgb_chan[3] = { 0, 1, 2 };
 
         rc = 0;
@@ -489,9 +476,7 @@ i_writeppm_wiol(i_img *im, io_glue *ig) {
       unsigned char *data = mymalloc(im->xsize);
       if (data != NULL) {
         int y = 0;
-        int x, ch;
         int chan = 0;
-        unsigned char *p;
 
         rc = 0;
         while (y < im->ysize && rc >= 0) {