[dovecot-cvs] dovecot/src/lib-index mail-index-view.c, 1.44.2.6, 1.44.2.7

tss at dovecot.org tss at dovecot.org
Thu Jan 25 17:13:38 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv19604

Modified Files:
      Tag: branch_1_0
	mail-index-view.c 
Log Message:
lookup_uid_range(): Last change could have caused the returned seq2 to be
too high, causing all kinds of problems.



Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.44.2.6
retrieving revision 1.44.2.7
diff -u -d -r1.44.2.6 -r1.44.2.7
--- mail-index-view.c	24 Jan 2007 20:45:07 -0000	1.44.2.6
+++ mail-index-view.c	25 Jan 2007 17:13:36 -0000	1.44.2.7
@@ -300,8 +300,6 @@
 
 	if (uid == 1) {
 		/* optimization: the message can be only the first one */
-		if (view->hdr.messages_count == 0)
-			return 0;
 		return 1;
 	}
 	rec_base = view->map->records;
@@ -321,12 +319,7 @@
 		else
 			break;
 	}
-	if (idx == view->hdr.messages_count) {
-		/* left_idx was initially messages_count */
-		if (idx == 0)
-			return 0;
-		idx--;
-	}
+	i_assert(idx < view->hdr.messages_count);
 
 	rec = CONST_PTR_OFFSET(rec_base, idx * record_size);
 	if (rec->uid != uid) {
@@ -353,6 +346,11 @@
 	if (mail_index_view_lock(view) < 0)
 		return -1;
 
+	if (view->hdr.messages_count == 0) {
+		*first_seq_r = *last_seq_r = 0;
+		return 0;
+	}
+
 	*first_seq_r = mail_index_bsearch_uid(view, first_uid, 0, 1);
 	if (*first_seq_r == 0 ||
 	    MAIL_INDEX_MAP_IDX(view->map, *first_seq_r-1)->uid > last_uid) {
@@ -372,14 +370,13 @@
 		return 0;
 	}
 
-	if (first_uid == last_uid) {
+	if (first_uid == last_uid)
 		*last_seq_r = *first_seq_r;
-		return 0;
+	else {
+		/* optimization - binary lookup only from right side: */
+		*last_seq_r = mail_index_bsearch_uid(view, last_uid,
+						     *first_seq_r, -1);
 	}
-
-	/* optimization - binary lookup only from right side: */
-	*last_seq_r = mail_index_bsearch_uid(view, last_uid,
-					     *first_seq_r + 1, -1);
 	i_assert(*last_seq_r >= *first_seq_r);
 	return 0;
 }



More information about the dovecot-cvs mailing list