all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Claudio Bley <claudio.bley@googlemail.com>
To: Emacs-devel <emacs-devel@gnu.org>
Subject: [PATCH v2 4/5] Fix parsing of NetPBM file comments
Date: Wed, 30 Oct 2013 13:43:46 +0100	[thread overview]
Message-ID: <8738njylml.wl%claudio.bley@gmail.com> (raw)
In-Reply-To: <cover.1383136381.git.claudio.bley@gmail.com>

Comments in NetPBM headers can occur in the middle of a token.

(see http://netpbm.sourceforge.net/doc/pbm.html)
---
 src/image.c | 51 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/src/image.c b/src/image.c
index dea3d35..afd54ac 100644
--- a/src/image.c
+++ b/src/image.c
@@ -5111,6 +5111,27 @@ pbm_image_p (Lisp_Object object)
 }
 
 
+/* Get next char skipping comments in Netpbm header.  Returns -1 at
+   end of input.  */
+
+static int
+pbm_next_char (unsigned char **s, unsigned char *end)
+{
+  int c = -1;
+
+  while (*s < end && (c = *(*s)++, c == '#'))
+    {
+      /* Skip to the next line break */
+      while (*s < end && (c = *(*s)++, c != '\n' && c != '\r'))
+        ;
+
+      c = -1;
+    }
+
+  return c;
+}
+
+
 /* Scan a decimal number from *S and return it.  Advance *S while
    reading the number.  END is the end of the string.  Value is -1 at
    end of input.  */
@@ -5120,28 +5141,16 @@ pbm_scan_number (unsigned char **s, unsigned char *end)
 {
   int c = 0, val = -1;
 
-  while (*s < end)
-    {
-      /* Skip white-space.  */
-      while (*s < end && (c = *(*s)++, c_isspace (c)))
-	;
+  /* Skip white-space.  */
+  while ((c = pbm_next_char (s, end)) != -1 && c_isspace (c))
+    ;
 
-      if (c == '#')
-	{
-	  /* Skip comment to end of line.  */
-	  while (*s < end && (c = *(*s)++, c != '\n'))
-	    ;
-	}
-      else if (c_isdigit (c))
-	{
-	  /* Read decimal number.  */
-	  val = c - '0';
-	  while (*s < end && (c = *(*s)++, c_isdigit (c)))
-	    val = 10 * val + c - '0';
-	  break;
-	}
-      else
-	break;
+  if (c_isdigit (c))
+    {
+      /* Read decimal number.  */
+      val = c - '0';
+      while ((c = pbm_next_char (s, end)) != -1 && c_isdigit (c))
+        val = 10 * val + c - '0';
     }
 
   return val;
-- 
1.8.4.msysgit.0



  parent reply	other threads:[~2013-10-30 12:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1383136381.git.claudio.bley@gmail.com>
2013-10-30 12:43 ` [PATCH v2 1/5] w32: define new jpeglib-version var in order to load the correct DLL at runtime Claudio Bley
2013-11-01  9:16   ` Eli Zaretskii
2013-10-30 12:43 ` [PATCH v2 2/5] w32: add support for recent PNG library version >= 1.5 Claudio Bley
2013-11-01  9:16   ` Eli Zaretskii
2013-10-30 12:43 ` [PATCH v2 3/5] w32: add support for default library names for libtiff Claudio Bley
2013-11-01  9:19   ` Eli Zaretskii
2013-10-30 12:43 ` Claudio Bley [this message]
2013-11-01  9:19   ` [PATCH v2 4/5] Fix parsing of NetPBM file comments Eli Zaretskii
2013-10-30 12:44 ` [PATCH v2 5/5] Fix file magic for pbm files with comments Claudio Bley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8738njylml.wl%claudio.bley@gmail.com \
    --to=claudio.bley@googlemail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.