On Thu, Jul 13, 2017 at 04:29:33PM +0200, Timothy Redaelli wrote:
> test_snprintf function (tests/test-util.c) tests snprintf with shorter length,
> but this emit a warning on GCC 7.0 or later.
> 
> This commit disables that warning on tests only.
> 
> Signed-off-by: Timothy Redaelli <[email protected]>

How about disabling it just for those lines of code?

--8<--------------------------cut here-------------------------->8--

From: Ben Pfaff <[email protected]>
Date: Thu, 13 Jul 2017 10:21:10 -0700
Subject: [PATCH] test-util: Avoid format truncation warning for snprintf()
 tests.

Reported-by: Timothy Redaelli <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
---
 tests/test-util.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tests/test-util.c b/tests/test-util.c
index e37c722829e0..9222355ec1b0 100644
--- a/tests/test-util.c
+++ b/tests/test-util.c
@@ -1116,11 +1116,21 @@ test_snprintf(struct ovs_cmdl_context *ctx OVS_UNUSED)
 {
     char s[16];
 
+#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
     ovs_assert(snprintf(s, 4, "abcde") == 5);
     ovs_assert(!strcmp(s, "abc"));
 
     ovs_assert(snprintf(s, 5, "abcde") == 5);
     ovs_assert(!strcmp(s, "abcd"));
+#if __GNUC__ >= 7
+#pragma GCC diagnostic pop
+#endif
 
     ovs_assert(snprintf(s, 6, "abcde") == 5);
     ovs_assert(!strcmp(s, "abcde"));
-- 
2.10.2

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to