[PATCH 01/10] test: add regression test for notmuch_message_has_maildir_flag

Subject: [PATCH 01/10] test: add regression test for notmuch_message_has_maildir_flag

Date: Wed, 8 Jul 2020 21:17:00 -0300

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


This passes the NULL return inside _ensure_maildir_flags does not
break anything. Probably this should be handled more explicitely.
---
 lib/message.cc         |  3 ++-
 test/T560-lib-error.sh | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lib/message.cc b/lib/message.cc
index 4e1be986..bb4b2fa1 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1732,7 +1732,8 @@ _ensure_maildir_flags (notmuch_message_t *message, bool force)
 	    message->maildir_flags = NULL;
 	}
     }
-
+    /* n_m_get_filenames returns NULL for errors, which terminates the
+     * loop */
     for (filenames = notmuch_message_get_filenames (message);
 	 notmuch_filenames_valid (filenames);
 	 notmuch_filenames_move_to_next (filenames)) {
diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index afb53346..59a59d82 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -550,4 +550,20 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "Handle read maildir flag with closed database"
+cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        notmuch_bool_t is_set = -1;
+        is_set = notmuch_message_has_maildir_flag (message, 'S');
+        printf("%d\n%d\n", message != NULL, is_set == FALSE || is_set == TRUE);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
-- 
2.27.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: