changeset 8155:b8feb139cf92 HEAD

strmap: Make sure the records array is always zero-terminated.
author Timo Sirainen <tss@iki.fi>
date Fri, 05 Sep 2008 19:21:47 +0300
parents f15ce57d84d1
children f77a285629a5
files src/lib-index/mail-index-strmap.c src/lib-storage/index/index-thread.c
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-strmap.c	Fri Sep 05 12:40:28 2008 +0300
+++ b/src/lib-index/mail-index-strmap.c	Fri Sep 05 19:21:47 2008 +0300
@@ -789,6 +789,14 @@
 	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 @@
 	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 @@
 	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 @@
 	*_sync = NULL;
 
 	mail_index_strmap_view_reset(sync->view);
+	mail_index_strmap_zero_terminate(sync->view);
 	i_free(sync);
 }
--- a/src/lib-storage/index/index-thread.c	Fri Sep 05 12:40:28 2008 +0300
+++ b/src/lib-storage/index/index-thread.c	Fri Sep 05 19:21:47 2008 +0300
@@ -546,6 +546,9 @@
 			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)