[PATCH 2/3] lib: make notmuch_threads_valid return FALSE when passed NULL
authorDavid Bremner <david@tethera.net>
Thu, 23 Jan 2014 12:24:00 +0000 (08:24 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:59:13 +0000 (09:59 -0800)
07/3a1e02e61cbb6f879e5a0e77fb3faf842b910c [new file with mode: 0644]

diff --git a/07/3a1e02e61cbb6f879e5a0e77fb3faf842b910c b/07/3a1e02e61cbb6f879e5a0e77fb3faf842b910c
new file mode 100644 (file)
index 0000000..36da891
--- /dev/null
@@ -0,0 +1,87 @@
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 4A0B0431FD5\r
+       for <notmuch@notmuchmail.org>; Thu, 23 Jan 2014 04:24:42 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id G0ZlZ1IQvD8y for <notmuch@notmuchmail.org>;\r
+       Thu, 23 Jan 2014 04:24:36 -0800 (PST)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+       (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C56FA431FB6\r
+       for <notmuch@notmuchmail.org>; Thu, 23 Jan 2014 04:24:21 -0800 (PST)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1W6JKX-0006X4-BR; Thu, 23 Jan 2014 08:24:21 -0400\r
+Received: (nullmailer pid 17153 invoked by uid 1000); Thu, 23 Jan 2014\r
+       12:24:06 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] lib: make notmuch_threads_valid return FALSE when passed\r
+       NULL\r
+Date: Thu, 23 Jan 2014 08:24:00 -0400\r
+Message-Id: <1390479841-17045-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.8.5.2\r
+In-Reply-To: <1390479841-17045-1-git-send-email-david@tethera.net>\r
+References: <m2r47zrkkc.fsf@guru.guru-group.fi>\r
+       <1390479841-17045-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 23 Jan 2014 12:24:42 -0000\r
+\r
+Without this patch, the example code in the header docs crashes for certain\r
+invalid queries (see id:871u00oimv.fsf@approx.mit.edu)\r
+---\r
+ lib/notmuch.h | 2 ++\r
+ lib/query.cc  | 3 +++\r
+ 2 files changed, 5 insertions(+)\r
+\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 02604c5..68896ae 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -802,6 +802,8 @@ notmuch_query_destroy (notmuch_query_t *query);\r
+  * valid object. Whereas when this function returns FALSE,\r
+  * notmuch_threads_get will return NULL.\r
+  *\r
++ * If passed a NULL pointer, this function returns FALSE\r
++ *\r
+  * See the documentation of notmuch_query_search_threads for example\r
+  * code showing how to iterate over a notmuch_threads_t object.\r
+  */\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index ec60e2e..60ff8bd 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -462,6 +462,9 @@ notmuch_threads_valid (notmuch_threads_t *threads)\r
+ {\r
+     unsigned int doc_id;\r
\r
++    if (! threads)\r
++      return FALSE;\r
++\r
+     while (threads->doc_id_pos < threads->doc_ids->len) {\r
+       doc_id = g_array_index (threads->doc_ids, unsigned int,\r
+                               threads->doc_id_pos);\r
+-- \r
+1.8.5.2\r
+\r