dovecot-1.2: mail_index_lookup_ext*() didn't return properly ali...

dovecot at dovecot.org dovecot at dovecot.org
Sat Aug 30 14:40:06 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/cf2c4f3c636f
changeset: 8126:cf2c4f3c636f
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Aug 30 14:39:53 2008 +0300
description:
mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.

diffstat:

1 file changed, 37 insertions(+), 1 deletion(-)
src/lib-index/mail-index-transaction-view.c |   38 ++++++++++++++++++++++++++-

diffs (69 lines):

diff -r 81967ad7098f -r cf2c4f3c636f src/lib-index/mail-index-transaction-view.c
--- a/src/lib-index/mail-index-transaction-view.c	Sat Aug 30 13:32:14 2008 +0300
+++ b/src/lib-index/mail-index-transaction-view.c	Sat Aug 30 14:39:53 2008 +0300
@@ -15,6 +15,7 @@ struct mail_index_view_transaction {
 
 	struct mail_index_map *lookup_map;
 	struct mail_index_header hdr;
+	buffer_t *lookup_return_data;
 };
 
 static void tview_close(struct mail_index_view *view)
@@ -25,6 +26,8 @@ static void tview_close(struct mail_inde
 
 	if (tview->lookup_map != NULL)
 		mail_index_unmap(&tview->lookup_map);
+	if (tview->lookup_return_data != NULL)
+		buffer_free(&tview->lookup_return_data);
 
 	tview->super->close(view);
 	mail_index_transaction_unref(&t);
@@ -184,6 +187,38 @@ tview_get_lookup_map(struct mail_index_v
 			mail_index_map_clone(tview->view.index->map);
 	}
 	return tview->lookup_map;
+}
+
+static const void *
+tview_return_updated_ext(struct mail_index_view_transaction *tview,
+			 const void *data, uint32_t ext_id)
+{
+	const struct mail_index_ext *ext;
+	uint32_t ext_idx;
+
+	/* data begins with a 32bit sequence, followed by the actual
+	   extension data */
+	data = CONST_PTR_OFFSET(data, sizeof(uint32_t));
+
+	if (!mail_index_map_get_ext_idx(tview->lookup_map, ext_id, &ext_idx))
+		i_unreached();
+
+	ext = array_idx(&tview->lookup_map->extensions, ext_idx);
+	if (ext->record_align <= sizeof(uint32_t)) {
+		/* data is 32bit aligned already */
+		return data;
+	} else {
+		/* assume we want 64bit alignment - copy the data to
+		   temporary buffer and return it */
+		if (tview->lookup_return_data == NULL) {
+			tview->lookup_return_data =
+				buffer_create_dynamic(default_pool,
+						      ext->record_size + 64);
+		}
+		buffer_write(tview->lookup_return_data,
+			     0, data, ext->record_size);
+		return tview->lookup_return_data->data;
+	}
 }
 
 static void
@@ -210,7 +245,8 @@ tview_lookup_ext_full(struct mail_index_
 		    mail_index_seq_array_lookup(ext_buf, seq, &idx)) {
 			data = array_idx(ext_buf, idx);
 			*map_r = tview_get_lookup_map(tview);
-			*data_r = CONST_PTR_OFFSET(data, sizeof(uint32_t));
+			*data_r = tview_return_updated_ext(tview, data,
+							   ext_id);
 			return;
 		}
 	}


More information about the dovecot-cvs mailing list