Skip to content

Commit

Permalink
global: Code cleanup - avoid passing NULL to functions with non-null …
Browse files Browse the repository at this point in the history
…parameter
  • Loading branch information
sirainen committed Nov 25, 2016
1 parent 8dc068f commit 56c5e1c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/lib-dcrypt/test-stream.c
Expand Up @@ -213,7 +213,7 @@ void test_write_read_v1(void)

test_assert_idx(pos + siz <= sizeof(payload), pos);
if (pos + siz > sizeof(payload)) break;
test_assert_idx(memcmp(ptr, payload + pos, siz) == 0, pos);
test_assert_idx(siz == 0 || memcmp(ptr, payload + pos, siz) == 0, pos);
i_stream_skip(is_2, siz); pos += siz;
}

Expand Down Expand Up @@ -264,7 +264,7 @@ void test_write_read_v1_short(void)

test_assert_idx(pos + siz <= sizeof(payload), pos);
if (pos + siz > sizeof(payload)) break;
test_assert_idx(memcmp(ptr, payload + pos, siz) == 0, pos);
test_assert_idx(siz == 0 || memcmp(ptr, payload + pos, siz) == 0, pos);
i_stream_skip(is_2, siz); pos += siz;
}

Expand Down Expand Up @@ -357,7 +357,7 @@ void test_write_read_v2(void)

test_assert_idx(pos + siz <= sizeof(payload), pos);
if (pos + siz > sizeof(payload)) break;
test_assert_idx(memcmp(ptr, payload + pos, siz) == 0, pos);
test_assert_idx(siz == 0 || memcmp(ptr, payload + pos, siz) == 0, pos);
i_stream_skip(is_2, siz); pos += siz;
}

Expand Down Expand Up @@ -405,7 +405,7 @@ void test_write_read_v2_short(void)

test_assert_idx(pos + siz <= sizeof(payload), pos);
if (pos + siz > sizeof(payload)) break;
test_assert_idx(memcmp(ptr, payload + pos, siz) == 0, pos);
test_assert_idx(siz == 0 || memcmp(ptr, payload + pos, siz) == 0, pos);
i_stream_skip(is_2, siz); pos += siz;
}

Expand Down
8 changes: 5 additions & 3 deletions src/lib-index/mail-cache-lookup.c
Expand Up @@ -477,9 +477,11 @@ static void header_lines_save(struct header_lookup_context *ctx,

hdr_data = p_new(ctx->pool, struct header_lookup_data, 1);
hdr_data->data_size = data_size;
hdr_data->data = data_dup = data_size == 0 ? NULL :
p_malloc(ctx->pool, data_size);
memcpy(data_dup, CONST_PTR_OFFSET(field->data, pos), data_size);
if (data_size > 0) {
hdr_data->data = data_dup =
p_malloc(ctx->pool, data_size);
memcpy(data_dup, CONST_PTR_OFFSET(field->data, pos), data_size);
}

for (i = 0; i < lines_count; i++) {
hdr_line.line_num = lines[i];
Expand Down
3 changes: 2 additions & 1 deletion src/lib-storage/index/dbox-multi/mdbox-storage.c
Expand Up @@ -214,7 +214,8 @@ int mdbox_read_header(struct mdbox_mailbox *mbox,
return -1;
}
memset(hdr, 0, sizeof(*hdr));
memcpy(hdr, data, I_MIN(data_size, sizeof(*hdr)));
if (data_size > 0)
memcpy(hdr, data, I_MIN(data_size, sizeof(*hdr)));
*need_resize_r = data_size < sizeof(*hdr);
return 0;
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib-storage/index/index-mailbox-size.c
Expand Up @@ -57,8 +57,10 @@ static void vsize_header_refresh(struct mailbox_vsize_update *update)

mail_index_get_header_ext(update->view, update->box->vsize_hdr_ext_id,
&data, &size);
memcpy(&update->orig_vsize_hdr, data,
I_MIN(size, sizeof(update->orig_vsize_hdr)));
if (size > 0) {
memcpy(&update->orig_vsize_hdr, data,
I_MIN(size, sizeof(update->orig_vsize_hdr)));
}
if (size == sizeof(update->vsize_hdr))
memcpy(&update->vsize_hdr, data, sizeof(update->vsize_hdr));
else {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/buffer.c
Expand Up @@ -185,7 +185,8 @@ void buffer_write(buffer_t *_buf, size_t pos,
struct real_buffer *buf = (struct real_buffer *)_buf;

buffer_check_limits(buf, pos, data_size);
memcpy(buf->w_buffer + pos, data, data_size);
if (data_size > 0)
memcpy(buf->w_buffer + pos, data, data_size);
}

void buffer_append(buffer_t *buf, const void *data, size_t data_size)
Expand Down
6 changes: 4 additions & 2 deletions src/lib/istream.c
Expand Up @@ -593,8 +593,10 @@ int i_stream_read_data(struct istream *stream, const unsigned char **data_r,

void i_stream_compress(struct istream_private *stream)
{
memmove(stream->w_buffer, stream->w_buffer + stream->skip,
stream->pos - stream->skip);
if (stream->skip != stream->pos) {
memmove(stream->w_buffer, stream->w_buffer + stream->skip,
stream->pos - stream->skip);
}
stream->pos -= stream->skip;

stream->skip = 0;
Expand Down

0 comments on commit 56c5e1c

Please sign in to comment.