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 1BF6D431FBD for ; Wed, 22 Jan 2014 09:30:27 -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 okzLUm7lM6c7 for ; Wed, 22 Jan 2014 09:30:21 -0800 (PST) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 7C37F431FAF for ; Wed, 22 Jan 2014 09:30:21 -0800 (PST) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 2EF511000B3; Wed, 22 Jan 2014 19:30:12 +0200 (EET) From: Tomi Ollila To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH] lib: make notmuch_threads_valid return FALSE when passed NULL In-Reply-To: <1390408979-28606-1-git-send-email-david@tethera.net> References: <8738kgrxyf.fsf@zancas.localnet> <1390408979-28606-1-git-send-email-david@tethera.net> User-Agent: Notmuch/0.17+41~g8e7fabf (http://notmuchmail.org) Emacs/24.3.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain 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 17:30:27 -0000 On Wed, Jan 22 2014, David Bremner wrote: > Without this patch, the example code in the header docs crashes for certain > invalid queries (see id:871u00oimv.fsf@approx.mit.edu) > --- Looks good and seems to work: $ make ... $ notmuch show foo.. A Xapian exception occurred performing query: Unknown range operation Query string was: foo.. zsh: segmentation fault notmuch show foo.. $ ./notmuch show foo.. A Xapian exception occurred performing query: Unknown range operation Query string was: foo.. (i.e. no "segmentation fault" in the latter) Tomi > 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) This format seems to be consistent with surrounding code (vs. threads == NULL) > + 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