]> diplodocus.org Git - nmh/commitdiff
Fixed scan to handle empty files without violating an assert [Bug #51693].
authorDavid Levine <levinedl@acm.org>
Wed, 9 Aug 2017 00:10:49 +0000 (20:10 -0400)
committerDavid Levine <levinedl@acm.org>
Wed, 9 Aug 2017 00:10:49 +0000 (20:10 -0400)
NEWS
sbr/m_getfld.c
test/scan/test-scan

diff --git a/NEWS b/NEWS
index a59252a..1cb36eb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -122,7 +122,8 @@ BUG FIXES
   actually works in the absence of a Fcc header in the replied-to message.
 - A Content-ID is generated for message/external-body entities as required
   by RFC 2045, even if -nocontentid is supplied to mhbuild.
   actually works in the absence of a Fcc header in the replied-to message.
 - A Content-ID is generated for message/external-body entities as required
   by RFC 2045, even if -nocontentid is supplied to mhbuild.
-- Post will now expand aliases on a "From" line when doing a BCC (bug #51098)
+- post will now expand aliases on a "From" line when doing a BCC [Bug #51098].
+- scan can now handle empty files without violating an assert [Bug #51693].
 
 -------------------
 DEPRECATED FEATURES
 
 -------------------
 DEPRECATED FEATURES
index d74f386..31bad20 100644 (file)
@@ -432,17 +432,20 @@ leave_getfld (m_getfld_state_t s) {
 
 static size_t
 read_more (m_getfld_state_t s) {
 
 static size_t
 read_more (m_getfld_state_t s) {
-    /* Retain at least edelimlen characters that have already been
-       read so that we can back up to them in m_Eom(). */
-    ssize_t retain = s->edelimlen;
+    /* Retain at least edelimlen characters that have already been read,
+       if at least edelimlen have been read, so that we can back up to them
+       in m_Eom(). */
+    ssize_t retain = s->end - s->msg_buf < s->edelimlen ? 0 : s->edelimlen;
     size_t num_read;
 
     size_t num_read;
 
-    if (retain < s->end - s->readpos)
-        retain = s->end - s->readpos;
-    assert (retain <= s->readpos - s->msg_buf);
+    if (retain > 0) {
+        if (retain < s->end - s->readpos)
+            retain = s->end - s->readpos;
+        assert (retain <= s->readpos - s->msg_buf);
 
 
-    /* Move what we want to retain at end of the buffer to the beginning. */
-    memmove (s->msg_buf, s->readpos - retain, retain);
+        /* Move what we want to retain at end of the buffer to the beginning. */
+        memmove (s->msg_buf, s->readpos - retain, retain);
+    }
 
     s->readpos = s->msg_buf + retain;
     num_read = fread (s->readpos, 1, MSG_INPUT_SIZE, s->iob);
 
     s->readpos = s->msg_buf + retain;
     num_read = fread (s->readpos, 1, MSG_INPUT_SIZE, s->iob);
index dc0e225..00e383c 100755 (executable)
@@ -19,6 +19,9 @@ check_exit '-eq 1' scan -
 expected="$MH_TEST_DIR/$$.expected"
 actual="$MH_TEST_DIR/$$.actual"
 
 expected="$MH_TEST_DIR/$$.expected"
 actual="$MH_TEST_DIR/$$.actual"
 
+
+# check -width
+start_test '-width'
 cat >"$expected" <<EOF
    1  09/29 Test1              Testing message 1<<This is message number 1 >>
    2  09/29 Test2              Testing message 2<<This is message number 2 >>
 cat >"$expected" <<EOF
    1  09/29 Test1              Testing message 1<<This is message number 1 >>
    2  09/29 Test2              Testing message 2<<This is message number 2 >>
@@ -35,7 +38,9 @@ EOF
 run_prog scan +inbox -width 80 >"$actual" || exit 1
 check "$expected" "$actual"
 
 run_prog scan +inbox -width 80 >"$actual" || exit 1
 check "$expected" "$actual"
 
+
 # check highlighting
 # check highlighting
+start_test 'highlighting'
 cat >"$expected" <<EOF
    1  09/29 Test1              Testing message 1<<This is message number 1 >>\e[m
    2  09/29 Test2              Testing message 2<<This is message number 2 >>\e[m
 cat >"$expected" <<EOF
    1  09/29 Test1              Testing message 1<<This is message number 1 >>\e[m
    2  09/29 Test2              Testing message 2<<This is message number 2 >>\e[m
@@ -56,4 +61,10 @@ run_prog scan -form scan.highlighted -width 80 >"$actual" || exit 1
 check "$expected" "$actual"
 
 
 check "$expected" "$actual"
 
 
+# check null input
+start_test 'null input'
+run_test 'scan -format "" -file /dev/null' ''
+
+
+finish_test
 exit $failed
 exit $failed