]> diplodocus.org Git - nmh/commitdiff
m_getfld.c: Alter Ungetc() to die if it can't rewind.
authorRalph Corderoy <ralph@inputplus.co.uk>
Wed, 9 Aug 2017 13:49:53 +0000 (14:49 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Wed, 9 Aug 2017 13:49:53 +0000 (14:49 +0100)
It used to return EOF to the caller in this case, but none of the three
callers bothered checking.  And the other return value of a `peek' of
the character that would next be read was also unused.

sbr/m_getfld.c

index 2458c3e..08d9eb0 100644 (file)
@@ -525,17 +525,15 @@ Peek (m_getfld_state_t s) {
 }
 
 /* If there's room, undo the consumption of one character from msg_buf,
- * rewinding so it's read next.  If the previous character isn't
- * available because we're at the start of msg_buf then return EOF, else
- * return the character that will be read next, a la Peek(). */
-static int
+ * rewinding so it's read next, else die. */
+static void
 Ungetc(m_getfld_state_t s)
 {
-    if (s->readpos == s->msg_buf) {
-       return EOF;
-    }
-    --s->bytes_read;
-    return *--s->readpos;
+    if (s->readpos == s->msg_buf)
+        adios(NULL, "Ungetc() at start of message buffer.");
+
+    s->readpos--;
+    s->bytes_read--;
 }