]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add and use MAIL_INDEX_MAP_HDR_OFFSET() helper macro
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 19 Jan 2021 10:48:16 +0000 (12:48 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 3 May 2021 13:01:05 +0000 (13:01 +0000)
src/doveadm/doveadm-dump-index.c
src/lib-index/mail-index-fsck.c
src/lib-index/mail-index-map-hdr.c
src/lib-index/mail-index-map.c
src/lib-index/mail-index-modseq.c
src/lib-index/mail-index-private.h
src/lib-index/mail-index-sync-keywords.c
src/lib-index/mail-index-view.c
src/lib-index/mail-index-write.c

index 765e5bd1d41490383797890ab2a3003b48002b01..c6648114372d4e5ca84906f86e35e5dbb5df2668 100644 (file)
@@ -212,7 +212,7 @@ static void dump_extension_header(struct mail_index *index,
        /* add some padding, since we don't bother to handle undersized
           headers correctly */
        buf = t_malloc0(MALLOC_ADD(ext->hdr_size, 128));
-       data = CONST_PTR_OFFSET(index->map->hdr_base, ext->hdr_offset);
+       data = MAIL_INDEX_MAP_HDR_OFFSET(index->map, ext->hdr_offset);
        memcpy(buf, data, ext->hdr_size);
        data = buf;
 
index 1c3531959cc8dad970ff7aa3d1cdce4b1ddd0777..a6b2eaf434b6c4dce42fd99b05dbbed82864010c 100644 (file)
@@ -157,7 +157,7 @@ mail_index_fsck_keywords(struct mail_index *index, struct mail_index_map *map,
 
        hdr_offset = ext_offset +
                mail_index_map_ext_hdr_offset(sizeof(MAIL_INDEX_EXT_KEYWORDS)-1);
-       kw_hdr = CONST_PTR_OFFSET(map->hdr_base, hdr_offset);
+       kw_hdr = MAIL_INDEX_MAP_HDR_OFFSET(map, hdr_offset);
        keywords_count = kw_hdr->keywords_count;
 
        kw_rec = (const void *)(kw_hdr + 1);
index ba48beaf63e3f9de6f75d261774bb398941ce944..b55c9cf82a97787dc78c7c93abccc6c678765c31 100644 (file)
@@ -80,7 +80,7 @@ int mail_index_map_parse_keywords(struct mail_index_map *map)
           - const char names[] * keywords_count
        */
        i_assert(ext->hdr_offset < map->hdr.header_size);
-       kw_hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
+       kw_hdr = MAIL_INDEX_MAP_HDR_OFFSET(map, ext->hdr_offset);
        kw_rec = (const void *)(kw_hdr + 1);
        name = (const char *)(kw_rec + kw_hdr->keywords_count);
 
index a8faaa02e0b9a5b07650eabff1c6b218372c4cf9..fbd7df662fc504525441d74afc9dd0a0e3a4fcdf 100644 (file)
@@ -122,7 +122,7 @@ int mail_index_map_ext_get_next(struct mail_index_map *map,
           - 64bit alignment padding
        */
        name_offset = offset + sizeof(*ext_hdr);
-       ext_hdr = CONST_PTR_OFFSET(map->hdr_base, offset);
+       ext_hdr = MAIL_INDEX_MAP_HDR_OFFSET(map, offset);
        if (offset + sizeof(*ext_hdr) >= map->hdr.header_size)
                return -1;
 
@@ -130,7 +130,7 @@ int mail_index_map_ext_get_next(struct mail_index_map *map,
        if (offset > map->hdr.header_size)
                return -1;
 
-       *name_r = t_strndup(CONST_PTR_OFFSET(map->hdr_base, name_offset),
+       *name_r = t_strndup(MAIL_INDEX_MAP_HDR_OFFSET(map, name_offset),
                            ext_hdr->name_size);
        if (strcmp(*name_r, str_sanitize(*name_r, SIZE_MAX)) != 0) {
                /* we allow only plain ASCII names, so this extension
@@ -356,8 +356,7 @@ static void mail_index_map_copy_header(struct mail_index_map *dest,
                      I_MIN(sizeof(dest->hdr), src->hdr.base_header_size));
        if (src != dest) {
                buffer_write(dest->hdr_copy_buf, src->hdr.base_header_size,
-                            CONST_PTR_OFFSET(src->hdr_base,
-                                             src->hdr.base_header_size),
+                            MAIL_INDEX_MAP_HDR_OFFSET(src, src->hdr.base_header_size),
                             src->hdr.header_size - src->hdr.base_header_size);
        }
        dest->hdr_base = buffer_get_modifiable_data(dest->hdr_copy_buf, NULL);
index c21dcd103bd04565d8d2cd6cf135157a81fe53b7..2f9bff01dab7c810a18700bd2f79a90b1bdb5136 100644 (file)
@@ -104,7 +104,7 @@ mail_index_map_get_modseq_header(struct mail_index_map *map)
        if (ext->hdr_size != sizeof(struct mail_index_modseq_header))
                return NULL;
 
-       return CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
+       return MAIL_INDEX_MAP_HDR_OFFSET(map, ext->hdr_offset);
 }
 
 uint64_t mail_index_map_modseq_get_highest(struct mail_index_map *map)
@@ -406,7 +406,7 @@ static void mail_index_modseq_sync_init(struct mail_index_modseq_sync *ctx)
        ext = array_idx(&map->extensions, ext_map_idx);
 
        /* get the current highest_modseq. don't change any modseq below it. */
-       hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
+       hdr = MAIL_INDEX_MAP_HDR_OFFSET(map, ext->hdr_offset);
 
        /* Scan logs for updates between ext_hdr.log_* .. view position.
           There are two reasons why there could be any:
@@ -498,7 +498,7 @@ static void mail_index_modseq_update_header(struct mail_index_modseq_sync *ctx)
        highest_modseq = mail_transaction_log_view_get_prev_modseq(view->log_view);
 
        ext = array_idx(&map->extensions, ext_map_idx);
-       old_modseq_hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
+       old_modseq_hdr = MAIL_INDEX_MAP_HDR_OFFSET(map, ext->hdr_offset);
 
        if (old_modseq_hdr->log_seq < log_seq ||
            (old_modseq_hdr->log_seq == log_seq &&
index e523e4dfded2ba282ea1cbb940cf091bb5456e7b..2a41753ea0977004375076f566a7b54945ec4394 100644 (file)
@@ -118,6 +118,8 @@ struct mail_index_record_map {
        uint32_t last_appended_uid;
 };
 
+#define MAIL_INDEX_MAP_HDR_OFFSET(map, hdr_offset) \
+       CONST_PTR_OFFSET((map)->hdr_base, hdr_offset)
 struct mail_index_map {
        struct mail_index *index;
        int refcount;
index 51e181beae4805729e306fdced7ec84f84acd934..1cbe07a765ec1d1a0caff08e75ecc1940fa36870 100644 (file)
@@ -45,7 +45,7 @@ keywords_get_header_buf(struct mail_index_map *map,
        struct mail_index_keyword_header new_kw_hdr;
        uint32_t offset;
 
-       kw_hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
+       kw_hdr = MAIL_INDEX_MAP_HDR_OFFSET(map, ext->hdr_offset);
        kw_rec = (const void *)(kw_hdr + 1);
        name = (const char *)(kw_rec + kw_hdr->keywords_count);
 
index d4d02ac23971a278a17d7b213abf6493e63c256c..6b544a6def6a916804eca6c0a03b612eeee913ca 100644 (file)
@@ -401,7 +401,7 @@ static void view_get_header_ext(struct mail_index_view *view,
        }
 
        ext = array_idx(&map->extensions, idx);
-       *data_r = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset);
+       *data_r = MAIL_INDEX_MAP_HDR_OFFSET(map, ext->hdr_offset);
        *data_size_r = ext->hdr_size;
 }
 
index 634e011405fcf5187a18b755b46fb5ced6d58c1b..5459ebadf074b960aa8a6855e1d95ce84a46bbd2 100644 (file)
@@ -80,7 +80,7 @@ static int mail_index_recreate(struct mail_index *index)
 
        base_size = I_MIN(map->hdr.base_header_size, sizeof(map->hdr));
        o_stream_nsend(output, &map->hdr, base_size);
-       o_stream_nsend(output, CONST_PTR_OFFSET(map->hdr_base, base_size),
+       o_stream_nsend(output, MAIL_INDEX_MAP_HDR_OFFSET(map, base_size),
                       map->hdr.header_size - base_size);
        o_stream_nsend(output, map->rec_map->records,
                       map->rec_map->records_count * map->hdr.record_size);