Skip to content

Commit

Permalink
global: Use i_realloc_type() wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed Jun 8, 2017
1 parent 6509aa7 commit e6d4f54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
17 changes: 7 additions & 10 deletions src/lib-index/mail-cache-fields.c
Expand Up @@ -133,13 +133,12 @@ void mail_cache_register_fields(struct mail_cache *cache,
return;

/* @UNSAFE */
cache->fields = i_realloc(cache->fields,
cache->fields_count * sizeof(*cache->fields),
new_idx * sizeof(*cache->fields));
cache->fields = i_realloc_type(cache->fields,
struct mail_cache_field_private,
cache->fields_count, new_idx);
cache->field_file_map =
i_realloc(cache->field_file_map,
cache->fields_count * sizeof(*cache->field_file_map),
new_idx * sizeof(*cache->field_file_map));
i_realloc_type(cache->field_file_map, uint32_t,
cache->fields_count, new_idx);

registered_count = cache->fields_count;
for (i = 0; i < fields_count; i++) {
Expand Down Expand Up @@ -349,10 +348,8 @@ int mail_cache_header_fields_read(struct mail_cache *cache)
new_fields_count = field_hdr->fields_count;
if (new_fields_count != 0) {
cache->file_field_map =
i_realloc(cache->file_field_map,
cache->file_fields_count *
sizeof(unsigned int),
new_fields_count * sizeof(unsigned int));
i_realloc_type(cache->file_field_map, unsigned int,
cache->file_fields_count, new_fields_count);
} else {
i_free_and_null(cache->file_field_map);
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib-index/mail-cache-transaction.c
Expand Up @@ -606,10 +606,10 @@ static int mail_cache_header_add_field(struct mail_cache_transaction_ctx *ctx,
if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) {
if (cache->file_fields_count <= field_idx) {
cache->file_field_map =
i_realloc(cache->file_field_map,
cache->file_fields_count *
sizeof(unsigned int),
(field_idx+1) * sizeof(unsigned int));
i_realloc_type(cache->file_field_map,
unsigned int,
cache->file_fields_count,
field_idx+1);
cache->file_fields_count = field_idx+1;
}
cache->file_field_map[field_idx] = field_idx;
Expand Down
10 changes: 4 additions & 6 deletions src/lib/ioloop-poll.c
Expand Up @@ -55,9 +55,8 @@ void io_loop_handle_add(struct io_file *io)

ctx->idx_count = nearest_power((unsigned int) fd+1);

ctx->fd_index = i_realloc(ctx->fd_index,
sizeof(int) * old_count,
sizeof(int) * ctx->idx_count);
ctx->fd_index = i_realloc_type(ctx->fd_index, int,
old_count, ctx->idx_count);
memset(ctx->fd_index + old_count, 0xff,
sizeof(int) * (ctx->idx_count-old_count));
}
Expand All @@ -68,9 +67,8 @@ void io_loop_handle_add(struct io_file *io)

ctx->fds_count = nearest_power(ctx->fds_count+1);

ctx->fds = i_realloc(ctx->fds,
sizeof(struct pollfd) * old_count,
sizeof(struct pollfd) * ctx->fds_count);
ctx->fds = i_realloc_type(ctx->fds, struct pollfd,
old_count, ctx->fds_count);
}

if (ctx->fd_index[fd] != -1) {
Expand Down

0 comments on commit e6d4f54

Please sign in to comment.