comparison src/lib-index/mail-index-transaction-view.c @ 8192:32aa972895cc HEAD

Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
author Timo Sirainen <tss@iki.fi>
date Thu, 11 Sep 2008 23:16:27 +0300
parents cf2c4f3c636f
children 413c70b0ae1d
comparison
equal deleted inserted replaced
8191:f14e68845b6b 8192:32aa972895cc
192 static const void * 192 static const void *
193 tview_return_updated_ext(struct mail_index_view_transaction *tview, 193 tview_return_updated_ext(struct mail_index_view_transaction *tview,
194 const void *data, uint32_t ext_id) 194 const void *data, uint32_t ext_id)
195 { 195 {
196 const struct mail_index_ext *ext; 196 const struct mail_index_ext *ext;
197 const struct mail_index_registered_ext *rext;
198 const struct mail_transaction_ext_intro *intro;
199 unsigned int record_align, record_size;
197 uint32_t ext_idx; 200 uint32_t ext_idx;
198 201
199 /* data begins with a 32bit sequence, followed by the actual 202 /* data begins with a 32bit sequence, followed by the actual
200 extension data */ 203 extension data */
201 data = CONST_PTR_OFFSET(data, sizeof(uint32_t)); 204 data = CONST_PTR_OFFSET(data, sizeof(uint32_t));
202 205
203 if (!mail_index_map_get_ext_idx(tview->lookup_map, ext_id, &ext_idx)) 206 if (!mail_index_map_get_ext_idx(tview->lookup_map, ext_id, &ext_idx)) {
204 i_unreached(); 207 /* we're adding the extension now. */
205 208 rext = array_idx(&tview->view.index->extensions, ext_id);
206 ext = array_idx(&tview->lookup_map->extensions, ext_idx); 209 record_align = ext->record_align;
210 record_size = ext->record_size;
211 } else {
212 ext = array_idx(&tview->lookup_map->extensions, ext_idx);
213 record_align = ext->record_align;
214 record_size = ext->record_size;
215 }
216
217 /* see if the extension has been resized within this transaction */
218 if (array_is_created(&tview->t->ext_resizes) &&
219 ext_id < array_count(&tview->t->ext_resizes)) {
220 intro = array_idx(&tview->t->ext_resizes, ext_id);
221 if (intro[ext_id].name_size != 0) {
222 record_align = intro->record_align;
223 record_size = intro->record_size;
224 }
225 }
226
207 if (ext->record_align <= sizeof(uint32_t)) { 227 if (ext->record_align <= sizeof(uint32_t)) {
208 /* data is 32bit aligned already */ 228 /* data is 32bit aligned already */
209 return data; 229 return data;
210 } else { 230 } else {
211 /* assume we want 64bit alignment - copy the data to 231 /* assume we want 64bit alignment - copy the data to