From e9d72d93a95251b1ac8b5b98f684cfd5db5fce6d Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 17 Jan 2022 14:17:58 +0900 Subject: [PATCH] Fix build warnings Change-Id: Ib5784f64fb176d2916f376ca4c0ca05d6e363c36 Signed-off-by: Youngjae Cho (cherry picked from commit 61dbc6b6e81fb35432bfd17960cb04433a5628cf) --- src/libcommon/ini-parser.c | 6 ++++-- tests/libcommon/test-common.c | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libcommon/ini-parser.c b/src/libcommon/ini-parser.c index a82192c..f08b28a 100644 --- a/src/libcommon/ini-parser.c +++ b/src/libcommon/ini-parser.c @@ -197,8 +197,10 @@ int libsys_config_parse_by_section(const char *fname, int cb(const struct parse_ prop = calloc(1, sizeof(struct section_property)); if (!prop) continue; - strncpy(prop->key, tmp_key, sizeof(prop->key) - 1); - strncpy(prop->value, tmp_value, sizeof(prop->value) - 1); + /* to suppress build warning of strncpy(-Wstringop-truncation), + * use memcpy instead. */ + memcpy(prop->key, tmp_key, sizeof(prop->key) - 1); + memcpy(prop->value, tmp_value, sizeof(prop->value) - 1); result.props = g_list_append(result.props, prop); } } diff --git a/tests/libcommon/test-common.c b/tests/libcommon/test-common.c index 76e770c..392830a 100644 --- a/tests/libcommon/test-common.c +++ b/tests/libcommon/test-common.c @@ -121,7 +121,7 @@ static void test_list_append_p(void **state) i = 0; SYS_G_LIST_FOREACH(head, elem, elem2) { - value = (int) elem2; + value = (int)(intptr_t) elem2; assert_int_equal(value, i++); } } @@ -142,7 +142,7 @@ static void test_list_prepend_p(void **state) i = 10; SYS_G_LIST_FOREACH(head, elem, elem2) { - value = (int) elem2; + value = (int)(intptr_t) elem2; assert_int_equal(value, --i); } } -- 2.34.1