From c8f12abc7382f3302ec9fc5152f1a711c4515f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 25 Jul 2020 18:23:11 +0200 Subject: [PATCH] Fix clang-11 issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tested with clang 11.0.0-++20200715043845+0e377e253c1-1~exp1 on Debian sid ../src/network/test-networkd-conf.c:104:56: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] test_config_parse_duid_rawdata_one(BYTES_0_128 + 2, 0, &(DUID){0, 128, BYTES_1_128}); ~~~~~~~~~~~~^~~ ../src/network/test-networkd-conf.c:104:56: note: use array indexing to silence this warning test_config_parse_duid_rawdata_one(BYTES_0_128 + 2, 0, &(DUID){0, 128, BYTES_1_128}); ^ & [ ] 1 warning generated. ../src/test/test-clock.c:52:17: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] ftruncate(fileno(f), 0); ^~~~~~~~~ ~~~~~~~~~~~~ 1 warning generated. (gdb) run Starting program: systemd/build/test-alloc-util [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". x1: 0x7fffffffd2d0 x2: 0x7fffffffdac0 y: 0x7fffffffd2cc z: 0x7fffffffd2c0 cleanup2(0x7fffffffd2cc) cleanup3(0x7fffffffd2c0) cleanup1(0x7fffffffdac0) cleanup1(0x7fffffffd2d0) *** buffer overflow detected ***: terminated Program received signal SIGABRT, Aborted. __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) bt full set = {__val = {0, 18446744073709551615, 0, 0, 0, 0, 140737348658240, 140737348659520, 0, 0, 0, 0, 0, 0, 0, 0}} pid = tid = ret = save_stage = 1 act = {__sigaction_handler = {sa_handler = 0x22ff0, sa_sigaction = 0x22ff0}, sa_mask = {__val = {140737349888603, 4217127, 4217127, 4217127, 4217127, 4217383, 0, 0, 0, 0, 143329, 143344, 140737351162752, 8959, 18446744073709551328, 4289072}}, sa_flags = -138460788, sa_restorer = 0xffffffffffffffff} sigs = {__val = {32, 0 }} ap = {{gp_offset = 24, fp_offset = 0, overflow_arg_area = 0x7fffffffd280, reg_save_area = 0x7fffffffd210}} fd = list = nlist = cp = No locals. No locals. No locals. No locals. No locals. l = 0 No locals. p1 = 0x405500 "\223Nd\n\351\301mA\214\262A\247\306b\276\317\327\353\346k\035\024\273{\276&!kλ\233\217\t\207\276\327\347\351\355\307R\276\063{\235w=\237E\357\277KL\245\374\245\066M\201+\333\064\272\332g>1<@" p2 = i = No locals. --- src/network/test-networkd-conf.c | 2 +- src/test/test-alloc-util.c | 3 +++ src/test/test-clock.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/network/test-networkd-conf.c b/src/network/test-networkd-conf.c index 2007acb781..5d338e6f1a 100644 --- a/src/network/test-networkd-conf.c +++ b/src/network/test-networkd-conf.c @@ -101,7 +101,7 @@ static void test_config_parse_duid_rawdata(void) { test_config_parse_duid_rawdata_one("11::", 0, &(DUID){0, 1, {0x11}}); /* FIXME: should this be an error? */ test_config_parse_duid_rawdata_one("abcdef", 0, &(DUID){}); test_config_parse_duid_rawdata_one(BYTES_0_128, 0, &(DUID){}); - test_config_parse_duid_rawdata_one(BYTES_0_128 + 2, 0, &(DUID){0, 128, BYTES_1_128}); + test_config_parse_duid_rawdata_one(&BYTES_0_128[2], 0, &(DUID){0, 128, BYTES_1_128}); } static void test_config_parse_hwaddr(void) { diff --git a/src/test/test-alloc-util.c b/src/test/test-alloc-util.c index d85f705504..72356aeaa4 100644 --- a/src/test/test-alloc-util.c +++ b/src/test/test-alloc-util.c @@ -136,6 +136,9 @@ static void test_cleanup_order(void) { static void test_auto_erase_memory(void) { _cleanup_(erase_and_freep) uint8_t *p1, *p2; + /* print address of p2, else e.g. clang-11 will optimize it out */ + log_debug("p1: %p p2: %p", &p1, &p2); + assert_se(p1 = new(uint8_t, 1024)); assert_se(p2 = new(uint8_t, 1024)); diff --git a/src/test/test-clock.c b/src/test/test-clock.c index e5a3de8a59..271d465546 100644 --- a/src/test/test-clock.c +++ b/src/test/test-clock.c @@ -49,7 +49,7 @@ static void test_clock_is_localtime(void) { log_info("scenario #%zu:, expected result %i", i, scenarios[i].expected_result); log_info("%s", scenarios[i].contents); rewind(f); - ftruncate(fileno(f), 0); + assert_se(ftruncate(fileno(f), 0) == 0); assert_se(write_string_stream(f, scenarios[i].contents, WRITE_STRING_FILE_AVOID_NEWLINE) == 0); assert_se(clock_is_localtime(adjtime) == scenarios[i].expected_result); }