[PATCH 64/72] multipath tests: util: fix clang strlcpy warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Wilck <mwilck@xxxxxxxx>

clang erroneously thought that we were using the size of the source
for the destination, while they are equal. Trick it into accepting
the code.

Signed-off-by: Martin Wilck <mwilck@xxxxxxxx>
---
 tests/util.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/tests/util.c b/tests/util.c
index 4e04a480..7c486fca 100644
--- a/tests/util.c
+++ b/tests/util.c
@@ -328,11 +328,12 @@ static void test_strlcpy_5(void **state)
 {
 	char *tst;
 	int rc;
+	const int sz = sizeof(src_str);
 
-	tst = malloc(sizeof(src_str));
+	tst = malloc(sz);
 	memset(tst, 'f', sizeof(src_str));
 
-	rc = strlcpy(tst, src_str, sizeof(src_str));
+	rc = strlcpy(tst, src_str, sz);
 	assert_int_equal(rc, strlen(src_str));
 	assert_string_equal(src_str, tst);
 
@@ -344,15 +345,16 @@ static void test_strlcpy_6(void **state)
 {
 	char *tst;
 	int rc;
+	const int sz = sizeof(src_str);
 
-	tst = malloc(sizeof(src_str) + 2);
-	memset(tst, 'f', sizeof(src_str) + 2);
+	tst = malloc(sz + 2);
+	memset(tst, 'f', sz + 2);
 
-	rc = strlcpy(tst, src_str, sizeof(src_str) + 2);
+	rc = strlcpy(tst, src_str, sz + 2);
 	assert_int_equal(rc, strlen(src_str));
 	assert_string_equal(src_str, tst);
-	assert_int_equal(tst[sizeof(src_str)], 'f');
-	assert_int_equal(tst[sizeof(src_str) + 1], 'f');
+	assert_int_equal(tst[sz], 'f');
+	assert_int_equal(tst[sz + 1], 'f');
 
 	free(tst);
 }
-- 
2.23.0


--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel



[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux