From: Ralph Corderoy Date: Sun, 16 Oct 2016 11:23:57 +0000 (+0100) Subject: Don't increment bytes_read if returning EOF. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/02e28520c4b36386258cc74a2534970c177ec6c2?hp=3028e444662122daf45e924d60874c0de619b478 Don't increment bytes_read if returning EOF. 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! --- diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index a7622b56..3a6d50eb 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -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