From df1b2c3ff9cea4b57a4b9f1688bef54998fda5a4 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 1 Nov 2016 12:35:08 +0200 Subject: [PATCH] lib-index: Don't waste 3 bytes of space in struct mail_index_record. It was always supposed to be used mainly for keywords, but it got broken many years ago and nobody noticed. --- src/lib-index/mail-index-sync-ext.c | 3 ++- src/lib-index/mail-index-sync-keywords.c | 2 +- src/lib-index/mail-index.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib-index/mail-index-sync-ext.c b/src/lib-index/mail-index-sync-ext.c index e40cec1d42..e097979df5 100644 --- a/src/lib-index/mail-index-sync-ext.c +++ b/src/lib-index/mail-index-sync-ext.c @@ -176,7 +176,7 @@ static void sync_ext_reorder(struct mail_index_map *map, uint32_t ext_map_idx, /* we simply try to use the extensions with largest alignment requirement first. FIXME: if the extension sizes don't match alignment, this may not give the minimal layout. */ - offset = sizeof(struct mail_index_record); + offset = MAIL_INDEX_RECORD_MIN_SIZE; max_align = sizeof(uint32_t); for (;;) { min_align = (uint16_t)-1; @@ -213,6 +213,7 @@ static void sync_ext_reorder(struct mail_index_map *map, uint32_t ext_map_idx, offset += max_align - (offset % max_align); } new_record_size = offset; + i_assert(new_record_size >= sizeof(struct mail_index_record)); /* copy the records to new buffer */ new_buffer_size = map->rec_map->records_count * new_record_size; diff --git a/src/lib-index/mail-index-sync-keywords.c b/src/lib-index/mail-index-sync-keywords.c index 7d5d0964f6..d7f6c0675b 100644 --- a/src/lib-index/mail-index-sync-keywords.c +++ b/src/lib-index/mail-index-sync-keywords.c @@ -225,7 +225,7 @@ keywords_update_records(struct mail_index_sync_map_ctx *ctx, i_assert(data_offset < ext->record_size); data_offset += ext->record_offset; - i_assert(data_offset >= sizeof(struct mail_index_record)); + i_assert(data_offset >= MAIL_INDEX_RECORD_MIN_SIZE); switch (type) { case MODIFY_ADD: diff --git a/src/lib-index/mail-index.h b/src/lib-index/mail-index.h index bae7ed5828..0c9c5d021a 100644 --- a/src/lib-index/mail-index.h +++ b/src/lib-index/mail-index.h @@ -105,6 +105,7 @@ struct mail_index_header { uint32_t day_first_uid[8]; }; +#define MAIL_INDEX_RECORD_MIN_SIZE (sizeof(uint32_t) + sizeof(uint8_t)) struct mail_index_record { uint32_t uid; uint8_t flags; /* enum mail_flags | enum mail_index_mail_flags */ -- 2.47.3