With the recent update in Fedora Rawhide, MinGW has
started freaking out about our use of strncpy():
In function 'virStrncpy',
inlined from 'virStrcpy' at ../../src/util/virstring.c:811:12:
../../src/util/virstring.c:789:11: error: 'strncpy' output truncated before
terminating nul copying as many bytes from a string as its length
[-Werror=stringop-truncation]
ret = strncpy(dest, src, n);
^~~~~~~~~~~~~~~~~~~~~
../../src/util/virstring.c: In function 'virStrcpy':
../../src/util/virstring.c:811:12: note: length computed here
return virStrncpy(dest, src, strlen(src), destbytes);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What the compiler is not detecting is that we perform
proper bound checking right before calling the function,
which makes our use of it perfectly safe.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
Kind of a big hammer, so if you have a better approach in mind
please don't hesitate to step forward.
cfg.mk | 2 +-
m4/virt-compile-warnings.m4 | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/cfg.mk b/cfg.mk
index 609ae869c2..d059f803eb 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1240,7 +1240,7 @@ exclude_file_name_regexp--sc_prohibit_setuid =
^src/util/virutil\.c$$
exclude_file_name_regexp--sc_prohibit_sprintf = \
^(cfg\.mk|docs/hacking\.html\.in|.*\.stp|.*\.pl)$$
-exclude_file_name_regexp--sc_prohibit_strncpy = ^src/util/virstring\.c$$
+exclude_file_name_regexp--sc_prohibit_strncpy =
^(src/util/virstring\.c|m4/virt-compile-warnings\.m4)$$
exclude_file_name_regexp--sc_prohibit_strtol = ^examples/.*$$
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index fc185aef38..7d71cf2504 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -243,6 +243,11 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
wantwarn="$wantwarn -Wno-suggest-attribute=pure"
wantwarn="$wantwarn -Wno-suggest-attribute=const"
+ # MinGW freaks out about our use of strncpy(), but we perform proper
+ # bound checking in our wrappers and prevent the underlying POSIX
+ # functions from being used directly through syntax-check
+ wantwarn="$wantwarn -Wno-stringop-truncation -Wno-stringop-overflow"
+
if test "$enable_werror" = "yes"
then
wantwarn="$wantwarn -Werror"
--
2.17.1