]> git.imager.perl.org - imager.git/commitdiff
avoid ignoring the result of i_io_getc()
authorTony Cook <tony@develop-help.com>
Sat, 5 Jan 2019 03:33:22 +0000 (14:33 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 5 Jan 2019 03:33:22 +0000 (14:33 +1100)
Coverity complained about *(ig->read_ptr++) because the result of the *
operator was ignored, which was deliberate.

I could simply had added a void cast, but given i_io_peekc(),
I could see a macro that skips the * being simpler to read, adding
i_io_nextc(), which is exposed as the nextc() method on Imager::IO
objects.

Changes
Imager.xs
iolayert.h
lib/Imager/IO.pod
pnm.c

diff --git a/Changes b/Changes
index 5d31334754d70fefeece7d602c668b15d4460adc..31b4d7fe3325005fc3fcb5ea265de15dc510974b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -99,6 +99,9 @@ High severity:
  - error diffusion now validates a custom error diffusion map and reports
    an error if it's bad.  CID 185288.
 
+ - avoid discarding the value of i_io_getc() when scanning numbers in
+   pnm.c.  CID 185293.
+
 [1] The first two build submissions ended up at the end of a ~400
 build queue, and seemed to have been cancelled by Coverity.  A build
 submitted on NYE went through in minutes.
index 2ff3c528421bdaf4dd768261435b1b95cebde9e4..cac322d52548c1752aa8fe4fee48deec6f1393bb 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -1514,6 +1514,10 @@ int
 i_io_getc(ig)
        Imager::IO ig
 
+void
+i_io_nextc(ig)
+       Imager::IO ig
+
 int
 i_io_putc(ig, c)
        Imager::IO ig
index d2dbb4dd02460a7965c9c36409241519536ce175..8d19451cec635dfffe4d14f956f769695f7671c7 100644 (file)
@@ -90,6 +90,10 @@ struct i_io_glue_t {
   ((ig)->read_ptr < (ig)->read_end ? \
      *((ig)->read_ptr++) : \
      i_io_getc_imp(ig))
+#define i_io_nextc(ig) \
+  ((void)((ig)->read_ptr < (ig)->read_end ?    \
+         ((ig)->read_ptr++, 0) :               \
+         i_io_getc_imp(ig)))
 #define i_io_peekc(ig) \
   ((ig)->read_ptr < (ig)->read_end ? \
    *((ig)->read_ptr) :              \
index 1d0501e20a3c91fe56022720383f05af1540f67c..487c39216873db34f0c47646f721d866161f1e4b 100644 (file)
@@ -149,6 +149,12 @@ Returns the ordinal of the byte or -1 on error or end of file.
     print chr($c);
   }
 
+=item nextc()
+
+Discard the next byte from the stream.
+
+Returns nothing.
+
 =item gets()
 
 =item gets($max_size)
diff --git a/pnm.c b/pnm.c
index 15fa4bb62909bfa925559ba6c012f108d2e25071..970994b9078366284254a79e268c1dfffd07a051 100644 (file)
--- a/pnm.c
+++ b/pnm.c
@@ -133,7 +133,7 @@ gnum(io_glue *ig, int *i) {
       return 0;
     }
     *i = work;
-    i_io_getc(ig);
+    i_io_nextc(ig);
   }
 
   return 1;