From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 207A2431FC2 for ; Wed, 22 Jan 2014 08:43:23 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Nn-n0HHyTOXP for ; Wed, 22 Jan 2014 08:43:15 -0800 (PST) Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A7602431FAF for ; Wed, 22 Jan 2014 08:43:15 -0800 (PST) Received: from remotemail by yantan.tethera.net with local (Exim 4.80) (envelope-from ) id 1W60tU-0002Ls-K2; Wed, 22 Jan 2014 12:43:12 -0400 Received: (nullmailer pid 28647 invoked by uid 1000); Wed, 22 Jan 2014 16:43:08 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH] lib: make notmuch_threads_valid return FALSE when passed NULL Date: Wed, 22 Jan 2014 12:42:59 -0400 Message-Id: <1390408979-28606-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <8738kgrxyf.fsf@zancas.localnet> References: <8738kgrxyf.fsf@zancas.localnet> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jan 2014 16:43:23 -0000 Without this patch, the example code in the header docs crashes for certain invalid queries (see id:871u00oimv.fsf@approx.mit.edu) --- lib/notmuch.h | 2 ++ lib/query.cc | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/notmuch.h b/lib/notmuch.h index 02604c5..68896ae 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -802,6 +802,8 @@ notmuch_query_destroy (notmuch_query_t *query); * valid object. Whereas when this function returns FALSE, * notmuch_threads_get will return NULL. * + * If passed a NULL pointer, this function returns FALSE + * * See the documentation of notmuch_query_search_threads for example * code showing how to iterate over a notmuch_threads_t object. */ diff --git a/lib/query.cc b/lib/query.cc index ec60e2e..60ff8bd 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -462,6 +462,9 @@ notmuch_threads_valid (notmuch_threads_t *threads) { unsigned int doc_id; + if (! threads) + return FALSE; + while (threads->doc_id_pos < threads->doc_ids->len) { doc_id = g_array_index (threads->doc_ids, unsigned int, threads->doc_id_pos); -- 1.8.5.2