[dovecot-cvs] dovecot/src/lib-index mail-index-view.c,1.54,1.55
tss at dovecot.org
tss at dovecot.org
Wed Jan 24 20:45:12 UTC 2007
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv24690
Modified Files:
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.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- mail-index-view.c 17 Jan 2007 16:17:42 -0000 1.54
+++ mail-index-view.c 24 Jan 2007 20:45:09 -0000 1.55
@@ -293,11 +293,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);
@@ -305,13 +305,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) {
@@ -325,13 +324,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) {
@@ -351,16 +350,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;
@@ -385,7 +381,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