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 5acc59f97b..ee8b378c41 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 7e0b176f68..0a61cb8680 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -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; } 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 1a536a51d1..a350de14ee 100644 --- a/src/lib/buffer.c +++ b/src/lib/buffer.c @@ -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) diff --git a/src/lib/istream.c b/src/lib/istream.c index 4727e87477..80ad7d221f 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -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;