diff options
author | Ben Pfaff <blp@ovn.org> | 2017-07-14 21:26:48 -0400 |
---|---|---|
committer | Russell Bryant <russell@ovn.org> | 2017-07-14 21:29:18 -0400 |
commit | fa792e4f62b829c23f60a743069d2114c7ae2e24 (patch) | |
tree | 39d32d59da4508166e5a114982e983a969aeb346 | |
parent | dd95bb5e1390f2a6e6e82208d8e4e23148de002d (diff) | |
download | openvswitch-fa792e4f62b829c23f60a743069d2114c7ae2e24.tar.gz |
test-util: Avoid format truncation warning for snprintf() tests.
Reported-by: Timothy Redaelli <tredaelli@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Signed-off-by: Russell Bryant <russell@ovn.org>
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | tests/automake.mk | 5 | ||||
-rw-r--r-- | tests/test-util.c | 10 |
3 files changed, 10 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac index ab002a0a0..23afe4c71 100644 --- a/configure.ac +++ b/configure.ac @@ -169,7 +169,6 @@ OVS_ENABLE_OPTION([-Wduplicated-cond]) OVS_ENABLE_OPTION([-Qunused-arguments]) OVS_CONDITIONAL_CC_OPTION([-Wno-unused], [HAVE_WNO_UNUSED]) OVS_CONDITIONAL_CC_OPTION([-Wno-unused-parameter], [HAVE_WNO_UNUSED_PARAMETER]) -OVS_CONDITIONAL_CC_OPTION([-Wno-format-truncation], [HAVE_WNO_FORMAT_TRUNCATION]) OVS_ENABLE_WERROR OVS_ENABLE_SPARSE OVS_CTAGS_IDENTIFIERS diff --git a/tests/automake.mk b/tests/automake.mk index 1011acf65..3118bbc27 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -364,11 +364,6 @@ tests_ovstest_SOURCES += \ endif tests_ovstest_LDADD = lib/libopenvswitch.la ovn/lib/libovn.la -tests_ovstest_CFLAGS = $(AM_CFLAGS) -if HAVE_WNO_FORMAT_TRUNCATION -tests_ovstest_CFLAGS += -Wno-format-truncation -endif - dist_check_SCRIPTS = tests/flowgen.pl noinst_PROGRAMS += tests/test-strtok_r diff --git a/tests/test-util.c b/tests/test-util.c index e37c72282..9222355ec 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")); |