From 27a80dcb677705f97019f9c15eece1d326c5b5e7 Mon Sep 17 00:00:00 2001 From: djcb Date: Tue, 25 Dec 2012 20:33:02 +0200 Subject: [PATCH] * handle the no-matches-found case correctly --- lib/mu-msg-iter.cc | 15 ++++++++++----- lib/mu-threader.c | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/mu-msg-iter.cc b/lib/mu-msg-iter.cc index 9b365ba5..c2c1ebda 100644 --- a/lib/mu-msg-iter.cc +++ b/lib/mu-msg-iter.cc @@ -71,6 +71,11 @@ public: _matches = _enq.get_mset (0, G_MAXINT); _matches.fetch(); + _cursor = _matches.begin(); + + if (_matches.empty()) + return; + _skip_dups = false; _thread_hash = mu_threader_calculate (this, _matches.size(), sortfield, descending); @@ -85,6 +90,7 @@ public: * non-scientific testing suggests. 5-10% or so */ if (_matches.size() <= MAX_FETCH_SIZE) _matches.fetch (); + } ~_MuMsgIter () { @@ -182,11 +188,10 @@ mu_msg_iter_new (XapianEnquire *enq, size_t maxnum, sortfield == MU_MSG_FIELD_ID_NONE, FALSE); try { - MuMsgIter *iter; - iter = new MuMsgIter ((Xapian::Enquire&)*enq, - maxnum, - sortfield, - flags); + MuMsgIter *iter (new MuMsgIter ((Xapian::Enquire&)*enq, + maxnum, + sortfield, + flags)); // note: we check if it's a dup even for the first message, // since we need its uid in the set for checking later messages if ((iter->skip_unreadable() && !is_msg_file_readable (iter)) || diff --git a/lib/mu-threader.c b/lib/mu-threader.c index 79932e9f..7e832bdd 100644 --- a/lib/mu-threader.c +++ b/lib/mu-threader.c @@ -71,6 +71,8 @@ mu_threader_calculate (MuMsgIter *iter, size_t matchnum, /* step 1 */ id_table = create_containers (iter); + if (matchnum == 0) + return id_table; /* just return an empty table */ /* step 2 -- the root_set is the list of children without parent */ root_set = find_root_set (id_table);