From 2aa07538bad3efb54309ada63fdaa1273ffbd1a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 11 Jul 2019 07:54:04 +0200 Subject: [PATCH] test: minor modernization Coverity was complaining that read() does not terminate the data. But we did that termination earlier, so covirity is wrong (CID#1402306, CID#1402340). Let's modernize the style a bit nevertheless. (size_t) cast is needed to avoid the warning about comparison, iff the value is not a constant. --- src/test/test-copy.c | 6 +++--- src/test/test-fileio.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 5f4bc39..731d599 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -52,8 +52,8 @@ static void test_copy_file_fd(void) { char in_fn[] = "/tmp/test-copy-file-fd-XXXXXX"; char out_fn[] = "/tmp/test-copy-file-fd-XXXXXX"; _cleanup_close_ int in_fd = -1, out_fd = -1; - char text[] = "boohoo\nfoo\n\tbar\n"; - char buf[64] = {0}; + const char *text = "boohoo\nfoo\n\tbar\n"; + char buf[64] = {}; log_info("%s", __func__); @@ -67,7 +67,7 @@ static void test_copy_file_fd(void) { assert_se(copy_file_fd(in_fn, out_fd, COPY_REFLINK) >= 0); assert_se(lseek(out_fd, SEEK_SET, 0) == 0); - assert_se(read(out_fd, buf, sizeof(buf)) == sizeof(text) - 1); + assert_se(read(out_fd, buf, sizeof buf) == (ssize_t) strlen(text)); assert_se(streq(buf, text)); unlink(in_fn); diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 211def8..1ad47a4 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -427,7 +427,7 @@ static void test_write_string_file(void) { static void test_write_string_file_no_create(void) { _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_file_no_create-XXXXXX"; _cleanup_close_ int fd; - char buf[64] = {0}; + char buf[64] = {}; fd = mkostemp_safe(fn); assert_se(fd >= 0); @@ -435,7 +435,7 @@ static void test_write_string_file_no_create(void) { assert_se(write_string_file("/a/file/which/does/not/exists/i/guess", "boohoo", 0) < 0); assert_se(write_string_file(fn, "boohoo", 0) == 0); - assert_se(read(fd, buf, sizeof(buf)) == STRLEN("boohoo\n")); + assert_se(read(fd, buf, sizeof buf) == (ssize_t) strlen("boohoo\n")); assert_se(streq(buf, "boohoo\n")); } -- 2.7.4