Skip to content

Commit

Permalink
lib,lib-test: stop calling memcmp and memcpy with NULL in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrannanj authored and GitLab committed Aug 11, 2016
1 parent d4488f3 commit 76b0023
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/lib-test/test-common.c
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/test-istream-base64-decoder.c
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/test-istream-crlf.c
Expand Up @@ -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);
Expand Down

0 comments on commit 76b0023

Please sign in to comment.