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

tss at dovecot.org tss at dovecot.org
Wed Jan 24 20:45:09 UTC 2007


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

Modified Files:
      Tag: branch_1_0
	mail-index-view.c 
Log Message:
Crashfix



Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.44.2.5
retrieving revision 1.44.2.6
diff -u -d -r1.44.2.5 -r1.44.2.6
--- mail-index-view.c	17 Jan 2007 16:17:38 -0000	1.44.2.5
+++ mail-index-view.c	24 Jan 2007 20:45:07 -0000	1.44.2.6
@@ -290,11 +290,11 @@
 }
 
 static uint32_t mail_index_bsearch_uid(struct mail_index_view *view,
-				       uint32_t uid, uint32_t *left_idx_p,
+				       uint32_t uid, uint32_t left_idx,
 				       int nearest_side)
 {
 	const struct mail_index_record *rec_base, *rec;
-	uint32_t idx, left_idx, right_idx, record_size;
+	uint32_t idx, right_idx, record_size;
 
 	i_assert(view->hdr.messages_count <= view->map->records_count);
 
@@ -302,13 +302,12 @@
 		/* optimization: the message can be only the first one */
 		if (view->hdr.messages_count == 0)
 			return 0;
-		*left_idx_p = 1;
 		return 1;
 	}
 	rec_base = view->map->records;
 	record_size = view->map->hdr.record_size;
 
-	idx = left_idx = *left_idx_p;
+	idx = left_idx;
 	right_idx = view->hdr.messages_count;
 
 	while (left_idx < right_idx) {
@@ -322,13 +321,13 @@
 		else
 			break;
 	}
-
 	if (idx == view->hdr.messages_count) {
-		/* no messages available */
-		return 0;
+		/* left_idx was initially messages_count */
+		if (idx == 0)
+			return 0;
+		idx--;
 	}
 
-        *left_idx_p = left_idx;
 	rec = CONST_PTR_OFFSET(rec_base, idx * record_size);
 	if (rec->uid != uid) {
 		if (nearest_side > 0) {
@@ -348,16 +347,13 @@
 				  uint32_t first_uid, uint32_t last_uid,
 				  uint32_t *first_seq_r, uint32_t *last_seq_r)
 {
-	uint32_t left_idx;
-
 	i_assert(first_uid > 0);
 	i_assert(first_uid <= last_uid);
 
 	if (mail_index_view_lock(view) < 0)
 		return -1;
 
-	left_idx = 0;
-	*first_seq_r = mail_index_bsearch_uid(view, first_uid, &left_idx, 1);
+	*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) {
 		*first_seq_r = *last_seq_r = 0;
@@ -382,7 +378,8 @@
 	}
 
 	/* optimization - binary lookup only from right side: */
-	*last_seq_r = mail_index_bsearch_uid(view, last_uid, &left_idx, -1);
+	*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