]> git.notmuchmail.org Git - notmuch/commitdiff
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 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 25 Jan 2014 00:20:54 +0000 (20:20 -0400)
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
lib/query.cc

index 02604c5645c3c881ec490c6ed82a9a02601873d7..68896ae75afeeaa27347a284540160833bcd59ad 100644 (file)
@@ -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.
  *
  * 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.
  */
  * See the documentation of notmuch_query_search_threads for example
  * code showing how to iterate over a notmuch_threads_t object.
  */
index ec60e2e45c01226a9ed326b8af22f1add8b77c8b..60ff8bd9a39e1707e12a4e96cff99890b00d669b 100644 (file)
@@ -462,6 +462,9 @@ notmuch_threads_valid (notmuch_threads_t *threads)
 {
     unsigned int doc_id;
 
 {
     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);
     while (threads->doc_id_pos < threads->doc_ids->len) {
        doc_id = g_array_index (threads->doc_ids, unsigned int,
                                threads->doc_id_pos);