]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib,lib-test: stop calling memcmp and memcpy with NULL in tests
authorMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Mon, 25 Jul 2016 07:24:44 +0000 (10:24 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 15 Aug 2016 13:24:07 +0000 (16:24 +0300)
src/lib-test/test-common.c
src/lib/test-istream-base64-decoder.c
src/lib/test-istream-crlf.c

index 270e0effff40e18a808a8a1c94fcaa97dec03c65..ffa627d3c0c16b3dd50427173c1d4cfae1c972ca 100644 (file)
@@ -72,8 +72,10 @@ static ssize_t test_read(struct istream_private *stream)
                        stream->buffer = stream->w_buffer;
                        stream->buffer_size = cur_max;
                }
-               memcpy(stream->w_buffer + new_skip_diff, tstream->orig_buffer,
-                      cur_max - new_skip_diff);
+               ssize_t size = cur_max - new_skip_diff;
+               if (size > 0)
+                       memcpy(stream->w_buffer + new_skip_diff,
+                               tstream->orig_buffer, (size_t)size);
 
                ret = cur_max - stream->pos;
                stream->pos = cur_max;
index 18489378479e97cac166fb66d8d50a22341a8f3e..ffdab55a262c018c3f6b1ec27bba56239782732a 100644 (file)
@@ -43,7 +43,9 @@ decode_test(const char *base64_input, const char *output, bool broken_input)
                    (input->stream_errno == EINVAL && broken_input));
 
        data = i_stream_get_data(input, &size);
-       test_assert(size == strlen(output) && memcmp(data, output, size) == 0);
+       test_assert(size == strlen(output));
+       if (size > 0)
+               test_assert(memcmp(data, output, size) == 0);
        i_stream_unref(&input);
        i_stream_unref(&input_data);
 }
index b6ed18bd3a0cb5e95f74fef8f9f8ec70dcbc03d0..1750da2bd873c9b2ace0749becaa642d5c87b56e 100644 (file)
@@ -66,7 +66,9 @@ static void test_istream_crlf_input(const char *input)
                                test_assert(pos + (unsigned int)ret1 == size);
                                pos += ret1;
                        }
-                       test_assert_idx(memcmp(data, str_data(output), size) == 0, j*10000+i);
+                       if (size > 0)
+                               test_assert_idx(memcmp(data, str_data(output),
+                                                       size) == 0, j*10000+i);
                }
                test_assert_idx(size == str_len(output), j*10000+i);
                i_stream_unref(&crlf_istream);