]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
strmap: Make sure the records array is always zero-terminated.
authorTimo Sirainen <tss@iki.fi>
Fri, 5 Sep 2008 16:21:47 +0000 (19:21 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 5 Sep 2008 16:21:47 +0000 (19:21 +0300)
--HG--
branch : HEAD

src/lib-index/mail-index-strmap.c
src/lib-storage/index/index-thread.c

index bf7f4ea64e3ec77fbea757cd001665d1d0e4a25d..6f74c86e749b5f3ab86f08f7c7e31a76eec17b2f 100644 (file)
@@ -789,6 +789,14 @@ void mail_index_strmap_view_sync_add_unique(struct mail_index_strmap_view_sync *
        view->last_ref_index = ref_index;
 }
 
+static void
+mail_index_strmap_zero_terminate(struct mail_index_strmap_view *view)
+{
+       /* zero-terminate the records array */
+       (void)array_append_space(&view->recs);
+       array_delete(&view->recs, array_count(&view->recs)-1, 1);
+}
+
 static void mail_index_strmap_view_renumber(struct mail_index_strmap_view *view)
 {
        struct mail_index_strmap_read_context ctx;
@@ -835,6 +843,7 @@ static void mail_index_strmap_view_renumber(struct mail_index_strmap_view *view)
        i_assert(renumber_map[0] == 0);
        array_delete(&view->recs, dest, i-dest);
        array_delete(&view->recs_crc32, dest, i-dest);
+       mail_index_strmap_zero_terminate(view);
 
        /* notify caller of the renumbering */
        i_assert(str_idx <= view->next_str_idx);
@@ -1207,6 +1216,7 @@ void mail_index_strmap_view_sync_commit(struct mail_index_strmap_view_sync **_sy
        i_free(sync);
 
        (void)mail_index_strmap_write(view);
+       mail_index_strmap_zero_terminate(view);
 
        /* zero-terminate the records array */
        (void)array_append_space(&view->recs);
@@ -1220,5 +1230,6 @@ void mail_index_strmap_view_sync_rollback(struct mail_index_strmap_view_sync **_
        *_sync = NULL;
 
        mail_index_strmap_view_reset(sync->view);
+       mail_index_strmap_zero_terminate(sync->view);
        i_free(sync);
 }
index 8f8e5cb508ace99e7c04281d0711498188f9e17d..463577e7a6c78dd392d3a7f8be342e4792817922 100644 (file)
@@ -546,6 +546,9 @@ static int mail_thread_cache_sync_add(struct mail_thread_mailbox *tbox,
                        MAILBOX_SEARCH_RESULT_FLAG_QUEUE_SYNC);
 
        msgid_map = array_get(tbox->msgid_map, &count);
+       /* we're relying on the array being zero-terminated (outside used
+          count - kind of kludgy) */
+       i_assert(msgid_map[count].uid == 0);
        i = 0;
        while (i < count && mailbox_search_next(search_ctx, mail) > 0) {
                while (msgid_map[i].uid < mail->uid)