]> diplodocus.org Git - nmh/commitdiff
In m_getfld.c, cast the returns of valid characters to
authorDavid Levine <levinedl@acm.org>
Wed, 20 Feb 2013 01:45:25 +0000 (19:45 -0600)
committerDavid Levine <levinedl@acm.org>
Wed, 20 Feb 2013 01:45:25 +0000 (19:45 -0600)
unsigned char.  This differentiates them from EOF and matches
the behavior prior to the recent m_getfld() rework.  But that
behavior is very broken on 8-bit input.

sbr/m_getfld.c

index 40ae2289a2d8d40166908c7c274ee8cad74aec6d..c6716284d7f65732dc4575461e4aa75d82f0ad90 100644 (file)
@@ -443,6 +443,9 @@ read_more (m_getfld_state_t s) {
     return num_read;
 }
 
     return num_read;
 }
 
+/* The return values of the following functions are a bit
+   subtle.  They can return 0x00 - 0xff as a valid character,
+   but EOF is typically 0xffffffff. */
 static int
 Getc (m_getfld_state_t s) {
     if (s->end - s->readpos < 1) {
 static int
 Getc (m_getfld_state_t s) {
     if (s->end - s->readpos < 1) {
@@ -454,7 +457,7 @@ Getc (m_getfld_state_t s) {
     }
 
     ++s->bytes_read;
     }
 
     ++s->bytes_read;
-    return s->readpos < s->end  ?  *s->readpos++  :  EOF;
+    return s->readpos < s->end  ?  (unsigned char) *s->readpos++  :  EOF;
 }
 
 static int
 }
 
 static int
@@ -467,7 +470,7 @@ Peek (m_getfld_state_t s) {
        }
     }
 
        }
     }
 
-    return s->readpos < s->end  ?  *s->readpos  :  EOF;
+    return s->readpos < s->end  ?  (unsigned char) *s->readpos  :  EOF;
 }
 
 static int
 }
 
 static int
@@ -476,7 +479,7 @@ Ungetc (int c, m_getfld_state_t s) {
        return EOF;
     } else {
        --s->bytes_read;
        return EOF;
     } else {
        --s->bytes_read;
-       return *--s->readpos = c;
+       return *--s->readpos = (unsigned char) c;
     }
 }
 
     }
 }