]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail-index: trivial paranoia check in expunge loop
authorPhil Carmody <phil@dovecot.fi>
Mon, 2 Jun 2014 11:50:34 +0000 (14:50 +0300)
committerPhil Carmody <phil@dovecot.fi>
Mon, 2 Jun 2014 11:50:34 +0000 (14:50 +0300)
We will later be moving the zone between the current seqs and the
(end of the) previous seqs - this check ensures that the range is
indeed monotonic, and thus that zone is positive in size. It can
be zero right at the start, if the first seqs is (1,...)

Based on draft patch by Timo Sirainen.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib-index/mail-index-sync-update.c

index 5248cb2683fb3e2d23715ed9e5c586a1e5b8b306..f754e4d8a7e94cc98de001bcadf75bd2cdebcec9 100644 (file)
@@ -241,6 +241,7 @@ sync_expunge_range(struct mail_index_sync_map_ctx *ctx, const ARRAY_TYPE(seq_ran
        struct mail_index_map *map;
        const struct seq_range *range;
        unsigned int i, count;
+       uint32_t prev_seq2;
 
        map = mail_index_sync_get_atomic_map(ctx);
 
@@ -255,12 +256,15 @@ sync_expunge_range(struct mail_index_sync_map_ctx *ctx, const ARRAY_TYPE(seq_ran
        }
 
        /* Preparatory HACK - do this in forward order so the memmove()s are pessimal! */
+       prev_seq2 = 0;
        for (i = 0; i < count; i++) {
                uint32_t seq1 = range[i].seq1;
                uint32_t seq2 = range[i].seq2;
                struct mail_index_record *rec;
                uint32_t seq_count, seq;
 
+               i_assert(seq1 > prev_seq2);
+
                for (seq = seq1; seq <= seq2; seq++) {
                        rec = MAIL_INDEX_MAP_IDX(map, seq-1);
                        mail_index_sync_header_update_counts(ctx, rec->uid, rec->flags, 0);
@@ -275,6 +279,7 @@ sync_expunge_range(struct mail_index_sync_map_ctx *ctx, const ARRAY_TYPE(seq_ran
                map->rec_map->records_count -= seq_count;
                map->hdr.messages_count -= seq_count;
                mail_index_modseq_expunge(ctx->modseq_ctx, seq1, seq2);
+               prev_seq2 = seq2;
        }
 }