2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

tests: Fix build failure with Clang 18 due to -Wformat-truncation.

Cirrus CI is broken on FreeBSD 13.3 due to clang version update.
It now complains about snprintf truncation the same way GCC does:

  tests/test-util.c:1129:16: error: 'snprintf' will always be truncated;
          specified size is 5, but format string expands to at least 6
          [-Werror,-Wformat-truncation]

  1129 |     ovs_assert(snprintf(s, 5, "abcde") == 5);
       |                ^

Clang 17 on FreeBSD 14.0 works fine, but new Clang 18.1.4 on 13.3
fails to build.

Fix that by disabling Clang diagnostic the same way as we do for GCC.

Unfortunately, the pragma's are compiler-specific, so cannot be
combined, AFAIK.

Acked-by: Ales Musil <amusil@redhat.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Ilya Maximets 2024-04-26 18:35:21 +02:00
parent 8ce5c95f08
commit 1876b2796f

View File

@ -1116,12 +1116,16 @@ test_snprintf(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
char s[16];
/* GCC 7+ and Clang 18+ warn about the following calls that truncate
* a string using snprintf(). We're testing that truncation works
* properly, so temporarily disable the warning. */
#if __GNUC__ >= 7
/* GCC 7+ warns about the following calls that truncate a string using
* snprintf(). We're testing that truncation works properly, so
* temporarily disable the warning. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-truncation"
#endif
#if __clang_major__ >= 18
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-truncation"
#endif
ovs_assert(snprintf(s, 4, "abcde") == 5);
ovs_assert(!strcmp(s, "abc"));
@ -1130,6 +1134,9 @@ test_snprintf(struct ovs_cmdl_context *ctx OVS_UNUSED)
ovs_assert(!strcmp(s, "abcd"));
#if __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
#if __clang_major__ >= 18
#pragma clang diagnostic pop
#endif
ovs_assert(snprintf(s, 6, "abcde") == 5);