]> git.notmuchmail.org Git - notmuch/blobdiff - lib/query.cc
lib: Fix notmuch_query_search_threads to return NULL on any Xapian exception.
[notmuch] / lib / query.cc
index 9266d35f8fc517dbda11d3be9f68a0b47f7105da..59f4011b31d3a3f5616227d352b8f7234b05ee0f 100644 (file)
@@ -125,7 +125,9 @@ notmuch_query_search_messages (notmuch_query_t *query)
                              Xapian::QueryParser::FLAG_WILDCARD |
                              Xapian::QueryParser::FLAG_PURE_NOT);
 
-       if (strcmp (query_string, "") == 0) {
+       if (strcmp (query_string, "") == 0 ||
+           strcmp (query_string, "*") == 0)
+       {
            final_query = mail_query;
        } else {
            string_query = notmuch->query_parser->
@@ -146,6 +148,8 @@ notmuch_query_search_messages (notmuch_query_t *query)
        case NOTMUCH_SORT_MESSAGE_ID:
            enquire.set_sort_by_value (NOTMUCH_VALUE_MESSAGE_ID, FALSE);
            break;
+        case NOTMUCH_SORT_UNSORTED:
+           break;
        }
 
 #if DEBUG_QUERY
@@ -159,14 +163,16 @@ notmuch_query_search_messages (notmuch_query_t *query)
        messages->iterator = mset.begin ();
        messages->iterator_end = mset.end ();
 
+       return &messages->base;
+
     } catch (const Xapian::Error &error) {
        fprintf (stderr, "A Xapian exception occurred performing query: %s\n",
                 error.get_msg().c_str());
        fprintf (stderr, "Query string was: %s\n", query->query_string);
        notmuch->exception_reported = TRUE;
+       talloc_free (messages);
+       return NULL;
     }
-
-    return &messages->base;
 }
 
 notmuch_bool_t
@@ -243,6 +249,10 @@ notmuch_query_search_threads (notmuch_query_t *query)
                                              free, NULL);
 
     threads->messages = notmuch_query_search_messages (query);
+    if (threads->messages == NULL) {
+           talloc_free (threads);
+           return NULL;
+    }
 
     threads->thread_id = NULL;
 
@@ -297,7 +307,8 @@ notmuch_threads_get (notmuch_threads_t *threads)
     return _notmuch_thread_create (threads->query,
                                   threads->query->notmuch,
                                   threads->thread_id,
-                                  threads->query->query_string);
+                                  threads->query->query_string,
+                                  threads->query->sort);
 }
 
 void
@@ -333,7 +344,9 @@ notmuch_query_count_messages (notmuch_query_t *query)
                              Xapian::QueryParser::FLAG_WILDCARD |
                              Xapian::QueryParser::FLAG_PURE_NOT);
 
-       if (strcmp (query_string, "") == 0) {
+       if (strcmp (query_string, "") == 0 ||
+           strcmp (query_string, "*") == 0)
+       {
            final_query = mail_query;
        } else {
            string_query = notmuch->query_parser->