[PATCH] lib: make notmuch_threads_valid return FALSE when passed NULL

Tomi Ollila tomi.ollila at iki.fi
Wed Jan 22 09:30:11 PST 2014


On Wed, Jan 22 2014, David Bremner <david at tethera.net> wrote:

> Without this patch, the example code in the header docs crashes for certain
> invalid queries (see id:871u00oimv.fsf at 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


More information about the notmuch mailing list