]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Code cleanup - avoid passing NULL to functions with non-null parameter
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 18 Nov 2016 23:54:14 +0000 (01:54 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 25 Nov 2016 13:28:53 +0000 (15:28 +0200)
src/lib-dcrypt/test-stream.c
src/lib-index/mail-cache-lookup.c
src/lib-storage/index/dbox-multi/mdbox-storage.c
src/lib-storage/index/index-mailbox-size.c
src/lib/buffer.c
src/lib/istream.c

index aa5a7f48dae6fe728a21eeaa87f110605b35f028..51913e989947384f450e42e6c478f410d443dfbf 100644 (file)
@@ -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;
        }
 
index 5acc59f97b06538c291c0e440c92b348325cd0ba..ee8b378c4169dcfc3ebaa98250542273a83bd26d 100644 (file)
@@ -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];
index 7e0b176f68d06e21838084ceecbede6525d3743d..0a61cb86803fb6ef115d6a4098aecbdedf7421bb 100644 (file)
@@ -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;
 }
index 1fd4008dfd385304f1e7aa65805cbdea806644b8..0153a094b453ff70a688f3d70633084d70a1517d 100644 (file)
@@ -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 {
index 1a536a51d122b68b012edaa582d0bcb0a38bb9d4..a350de14eefd74429c9016f96696c9cc63d4b9b0 100644 (file)
@@ -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)
index 4727e874771eddd0dd17ecbd442ad6e0e69e3b4e..80ad7d221f1a4ebb339ea3a6b68f238cad24fd21 100644 (file)
@@ -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;