From: Michael Jeanson Date: Fri, 26 Mar 2021 18:36:30 +0000 (-0400) Subject: fix: use proper format specifiers in tests (-Wformat) X-Git-Tag: v2.13.0-rc1~181 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3c99db226fd7e6100f300549cdcb3e8dc7d4c270;p=lttng-ust.git fix: use proper format specifiers in tests (-Wformat) Also rework the snprintf test to not use a 'gnu_printf' style format string as the function is annotated as expecting 'printf' style. Change-Id: Idca3a4003bcb06c70795bff399a7698fada041ca Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/tests/unit/snprintf/snprintf.c b/tests/unit/snprintf/snprintf.c index a2fbdc96..539bb0ac 100644 --- a/tests/unit/snprintf/snprintf.c +++ b/tests/unit/snprintf/snprintf.c @@ -13,19 +13,14 @@ int main() { char buf[100]; - char *expected; - char test_fmt_str[] = "header %d, %s, %03d, '%3$*d'"; - char escaped_test_fmt_str[] = "header %%d, %%s, %%03d, '%%3$*d'"; + const char expected_str[] = "header 9999, hello, 005, ' 9'"; + const char test_fmt_str[] = "header %d, %s, %03d, '%*d'"; plan_tests(1); - expected = "header 9999, hello, 005, ' 9'"; - ust_safe_snprintf(buf, 99, test_fmt_str, 9999, "hello", 5, 9); + ust_safe_snprintf(buf, 99, test_fmt_str, 9999, "hello", 5, 5, 9); - char test_desc_fmt_str[] = "Got expected output string with format string \"%s\""; - char test_desc[sizeof(escaped_test_fmt_str) + sizeof(test_desc_fmt_str) - 1]; - sprintf(test_desc, test_desc_fmt_str, escaped_test_fmt_str); - ok(strcmp(buf, expected) == 0, test_desc); + ok(strcmp(buf, expected_str) == 0, "Got expected output string with format string \"%s\"", test_fmt_str); return exit_status(); } diff --git a/tests/unit/ust-elf/ust-elf.c b/tests/unit/ust-elf/ust-elf.c index a1230b20..0073a999 100644 --- a/tests/unit/ust-elf/ust-elf.c +++ b/tests/unit/ust-elf/ust-elf.c @@ -4,6 +4,7 @@ * Copyright (C) 2015 Antoine Busque */ +#include #include #include #include @@ -76,7 +77,7 @@ void test_elf(const char *test_dir, const char *arch, uint64_t exp_memsz, ret = lttng_ust_elf_get_memsz(elf, &memsz); ok(ret == 0, "lttng_ust_elf_get_memsz returned successfully"); ok(memsz == exp_memsz, - "memsz - expected: %lu, got: %lu", + "memsz - expected: %" PRIu64 ", got: %" PRIu64, exp_memsz, memsz); ret = lttng_ust_elf_get_build_id(elf, &build_id, &build_id_len, @@ -84,7 +85,7 @@ void test_elf(const char *test_dir, const char *arch, uint64_t exp_memsz, ok(ret == 0, "lttng_ust_elf_get_build_id returned successfully"); ok(has_build_id == 1, "build id marked as found"); ok(build_id_len == BUILD_ID_LEN, - "build_id_len - expected: %u, got: %u", + "build_id_len - expected: %u, got: %zu", BUILD_ID_LEN, build_id_len); ok(memcmp(build_id, exp_build_id, build_id_len) == 0, "build_id has expected value");