From: David Levine Date: Tue, 6 Sep 2016 13:16:15 +0000 (-0400) Subject: Removed incorrect increment of read position pointer, which caused X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/965fd1e75b90d6af932f3553efb591eddd29a6a3?ds=inline;hp=-c Removed incorrect increment of read position pointer, which caused first character of some very short (less than 4 characters) message bodies to be dropped. It seems that the message needed to start with a "From " line to reveal the problem. --- 965fd1e75b90d6af932f3553efb591eddd29a6a3 diff --git a/docs/pending-release-notes b/docs/pending-release-notes index 37e6f70d..fce0f5c4 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -77,3 +77,5 @@ BUG FIXES - The format scanner no longer subtracts 1 from the width. This has the effect of no longer counting the trailing newline in the output of scan(1), inc(1), and the other programs that rely on the format scanner. +- The first character of some very short (less than 4 characters) message + bodies is no longer dropped. diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 9315059d..4da2f3ee 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -444,29 +444,21 @@ 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) { - if (read_more (s) == 0) { - /* Pretend that we read a character. That's what stdio does. */ - ++s->readpos; - return EOF; - } + if (s->end - s->readpos < 1 && read_more (s) == 0) { + return EOF; + } else { + ++s->bytes_read; + return s->readpos < s->end ? (unsigned char) *s->readpos++ : EOF; } - - ++s->bytes_read; - return s->readpos < s->end ? (unsigned char) *s->readpos++ : EOF; } static int Peek (m_getfld_state_t s) { - if (s->end - s->readpos < 1) { - if (read_more (s) == 0) { - /* Pretend that we read a character. That's what stdio does. */ - ++s->readpos; - return EOF; - } + if (s->end - s->readpos < 1 && read_more (s) == 0) { + return EOF; + } else { + return s->readpos < s->end ? (unsigned char) *s->readpos : EOF; } - - return s->readpos < s->end ? (unsigned char) *s->readpos : EOF; } static int diff --git a/test/inc/test-inc-scanout b/test/inc/test-inc-scanout index a3ec2593..4dd5a265 100755 --- a/test/inc/test-inc-scanout +++ b/test/inc/test-inc-scanout @@ -433,5 +433,65 @@ run_test "inc -width 60 -file $MH_TEST_DIR/msgbox -truncate" \ 25+ 04/15 me@example.com <>' rm -f "$MH_TEST_DIR/msgbox" +# check inc (m_getfld, actually) of very, very, very short message +cat >>"$MH_TEST_DIR/msgbox" <>' +rm -f "$MH_TEST_DIR/msgbox" + +# check inc (m_getfld, actually) of very, very short message +cat >>"$MH_TEST_DIR/msgbox" <>' +rm -f "$MH_TEST_DIR/msgbox" + +# check inc (m_getfld, actually) of very short message +cat >>"$MH_TEST_DIR/msgbox" <>' +rm -f "$MH_TEST_DIR/msgbox" + +# check inc (m_getfld, actually) of short message +cat >>"$MH_TEST_DIR/msgbox" <>' +rm -f "$MH_TEST_DIR/msgbox" + exit ${failed:-0}