dovecot-1.0: mail_index_lookup_ext*() didn't return properly ali...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Aug 30 14:40:45 EEST 2008
details: http://hg.dovecot.org/dovecot-1.0/rev/568687e4df02
changeset: 5567:568687e4df02
user: Timo Sirainen <tss at iki.fi>
date: Sat Aug 30 14:40:41 2008 +0300
description:
mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
diffstat:
1 file changed, 39 insertions(+), 1 deletion(-)
src/lib-index/mail-index-transaction-view.c | 40 ++++++++++++++++++++++++++-
diffs (70 lines):
diff -r 2d0520777c4b -r 568687e4df02 src/lib-index/mail-index-transaction-view.c
--- a/src/lib-index/mail-index-transaction-view.c Mon Aug 04 20:38:20 2008 -0400
+++ b/src/lib-index/mail-index-transaction-view.c Sat Aug 30 14:40:41 2008 +0300
@@ -13,12 +13,16 @@ struct mail_index_view_transaction {
struct mail_index_transaction *t;
struct mail_index_header hdr;
+ buffer_t *lookup_return_data;
};
static void _tview_close(struct mail_index_view *view)
{
struct mail_index_view_transaction *tview =
(struct mail_index_view_transaction *)view;
+
+ if (tview->lookup_return_data != NULL)
+ buffer_free(tview->lookup_return_data);
mail_index_transaction_unref(&tview->t);
tview->parent->close(view);
@@ -146,6 +150,39 @@ static int _tview_lookup_first(struct ma
}
return 0;
+}
+
+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->view.index->map,
+ ext_id, &ext_idx))
+ i_unreached();
+
+ ext = array_idx(&tview->view.index->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 int
@@ -172,7 +209,8 @@ _tview_lookup_ext_full(struct mail_index
if (array_is_created(ext_buf) &&
mail_index_seq_array_lookup(ext_buf, seq, &idx)) {
data = array_idx(ext_buf, idx);
- *data_r = CONST_PTR_OFFSET(data, sizeof(uint32_t));
+ *data_r = tview_return_updated_ext(tview, data,
+ ext_id);
return 1;
}
}
More information about the dovecot-cvs
mailing list