On Fri, Apr 26, 2024 at 6:35 PM Ilya Maximets <[email protected]> wrote:

> 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.
>
> Signed-off-by: Ilya Maximets <[email protected]>
> ---
>  tests/test-util.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/tests/test-util.c b/tests/test-util.c
> index 7d899fbbf..5d88d38f2 100644
> --- a/tests/test-util.c
> +++ b/tests/test-util.c
> @@ -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);
> --
> 2.44.0
>
> _______________________________________________
> dev mailing list
> [email protected]
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
>
Looks good to me, thanks.

Acked-by: Ales Musil <[email protected]>
-- 

Ales Musil

Senior Software Engineer - OVN Core

Red Hat EMEA <https://www.redhat.com>

[email protected]
<https://red.ht/sig>
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to