]> diplodocus.org Git - nmh/commitdiff
Don't increment bytes_read if returning EOF.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 11:23:57 +0000 (12:23 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 11:23:57 +0000 (12:23 +0100)
Don't know if this was actually causing a problem, or if it was wrong,
but bytes_read was always being incremented even if the later test
showed readpos was to be left unincremented and EOF returned instead.
All tests still pass so any breakage must be subtle!

sbr/m_getfld.c

index a7622b5..3a6d50e 100644 (file)
@@ -450,12 +450,12 @@ read_more (m_getfld_state_t s) {
    but EOF is typically 0xffffffff. */
 static int
 Getc (m_getfld_state_t s) {
-    if (s->end - s->readpos < 1  &&  read_more (s) == 0) {
+    if ((s->end - s->readpos < 1 && read_more (s) == 0) ||
+        s->readpos >= s->end)
         return EOF;
-    } else {
-        ++s->bytes_read;
-        return s->readpos < s->end  ?  (unsigned char) *s->readpos++  :  EOF;
-    }
+
+    s->bytes_read++;
+    return (unsigned char)*s->readpos++;
 }
 
 static int