[dovecot-cvs] dovecot/src/lib-index mail-index-view.c,1.55,1.56
tss at dovecot.org
tss at dovecot.org
Thu Jan 25 17:13:42 UTC 2007
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv19619
Modified Files:
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.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- mail-index-view.c 24 Jan 2007 20:45:09 -0000 1.55
+++ mail-index-view.c 25 Jan 2007 17:13:40 -0000 1.56
@@ -303,8 +303,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;
@@ -324,12 +322,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) {
@@ -356,6 +349,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) {
@@ -375,14 +373,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