Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4A0B0431FD5 for ; Thu, 23 Jan 2014 04:24:42 -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 G0ZlZ1IQvD8y for ; Thu, 23 Jan 2014 04:24:36 -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 C56FA431FB6 for ; Thu, 23 Jan 2014 04:24:21 -0800 (PST) Received: from remotemail by yantan.tethera.net with local (Exim 4.80) (envelope-from ) id 1W6JKX-0006X4-BR; Thu, 23 Jan 2014 08:24:21 -0400 Received: (nullmailer pid 17153 invoked by uid 1000); Thu, 23 Jan 2014 12:24:06 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/3] lib: make notmuch_threads_valid return FALSE when passed NULL Date: Thu, 23 Jan 2014 08:24:00 -0400 Message-Id: <1390479841-17045-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1390479841-17045-1-git-send-email-david@tethera.net> References: <1390479841-17045-1-git-send-email-david@tethera.net> 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: Thu, 23 Jan 2014 12:24:42 -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