]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail_index_lookup_uid_range(): don't crash if we look only UIDs larger than
authorTimo Sirainen <tss@iki.fi>
Tue, 25 May 2004 23:21:56 +0000 (02:21 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 25 May 2004 23:21:56 +0000 (02:21 +0300)
our next_uid

--HG--
branch : HEAD

src/lib-index/mail-index-view.c

index 9b7576c7234160aec37c518c4d6815d7c0462b25..da5118df2dfd46b3196ef471070fdcf1cb51165f 100644 (file)
@@ -267,6 +267,15 @@ int mail_index_lookup_uid_range(struct mail_index_view *view,
        if (mail_index_view_lock(view) < 0)
                return -1;
 
+       if (last_uid >= view->map->hdr->next_uid) {
+               last_uid = view->map->hdr->next_uid-1;
+               if (first_uid > last_uid) {
+                       *first_seq_r = 0;
+                       *last_seq_r = 0;
+                       return 0;
+               }
+       }
+
        left_idx = 0;
        *first_seq_r = mail_index_bsearch_uid(view, first_uid, &left_idx, 1);
        if (*first_seq_r == 0 ||
@@ -280,9 +289,6 @@ int mail_index_lookup_uid_range(struct mail_index_view *view,
                return 0;
        }
 
-       if (last_uid >= view->map->hdr->next_uid)
-               last_uid = view->map->hdr->next_uid-1;
-
        /* optimization - binary lookup only from right side: */
        *last_seq_r = mail_index_bsearch_uid(view, last_uid, &left_idx, -1);
        i_assert(*last_seq_r >= *first_seq_r);