From: Timo Sirainen Date: Fri, 18 Nov 2016 23:54:14 +0000 (+0200) Subject: global: Code cleanup - avoid passing NULL to functions with non-null parameter X-Git-Tag: 2.3.0.rc1~2526 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d404348751c19ac37cfb42375abdd3c5f298e30;p=thirdparty%2Fdovecot%2Fcore.git global: Code cleanup - avoid passing NULL to functions with non-null parameter --- diff --git a/src/lib-dcrypt/test-stream.c b/src/lib-dcrypt/test-stream.c index aa5a7f48da..51913e9899 100644 --- a/src/lib-dcrypt/test-stream.c +++ b/src/lib-dcrypt/test-stream.c @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/src/lib-index/mail-cache-lookup.c b/src/lib-index/mail-cache-lookup.c index 53be843baa..68bb126b7e 100644 --- a/src/lib-index/mail-cache-lookup.c +++ b/src/lib-index/mail-cache-lookup.c @@ -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]; diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index b690735c61..5d8d8cd8df 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -216,7 +216,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; } diff --git a/src/lib-storage/index/index-mailbox-size.c b/src/lib-storage/index/index-mailbox-size.c index 1fd4008dfd..0153a094b4 100644 --- a/src/lib-storage/index/index-mailbox-size.c +++ b/src/lib-storage/index/index-mailbox-size.c @@ -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 { diff --git a/src/lib/buffer.c b/src/lib/buffer.c index 61428160ad..9b5b945f68 100644 --- a/src/lib/buffer.c +++ b/src/lib/buffer.c @@ -180,7 +180,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) diff --git a/src/lib/istream.c b/src/lib/istream.c index 36829214fb..6878d6017e 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -602,8 +602,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;