[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/2] build: avoid warnings from gcc 4.2.1



OpenBSD ships with gcc 4.2.1, which annoyingly treats all format
strings as though they were also attribute((nonnull)).  The two
concepts are orthogonal, though, as evidenced by the number of
spurious warnings it generates on uses where we know that
virReportError specifically handles NULL instead of a format
string; worse, since we now force -Werror on git builds, it
prevents development builds on OpenBSD.

I hate to do this, as it disables ALL format checking on older
gcc, and therefore misses out on some useful checks (code that
happened to compile on Linux may still have type mismatches
when compiled on other platforms, as evidenced by the number
of times I have fixed formatting mismatches for uid_t as found
by warnings on Cygwin), but I don't see any other way to keep
-Werror alive and still compile on OpenBSD.

A more invasive change would be to make virReportError() mark
its format attribute as nonnull, and fix (a lot of) fallout;
we may end up doing that anyways as part of danpb's error
refactoring improvements, but not today.

* src/internal.h (ATTRIBUTE_FMT_PRINTF): Use preferred spellings.
* m4/virt-compile-warnings.m4 (-Wformat): Disable on older gcc.
---
 m4/virt-compile-warnings.m4 | 8 +++++++-
 src/internal.h              | 6 ++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 26f6134..c3ff962 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -110,8 +110,14 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     gl_WARN_ADD([-Wjump-misses-init])

     # GNULIB turns on -Wformat=2 which implies -Wformat-nonliteral,
-    # so we need to manually re-exclude it.
+    # so we need to manually re-exclude it.  Also, older gcc 4.2
+    # added an implied ATTRIBUTE_NONNULL on any parameter marked
+    # ATTRIBUTE_FMT_PRINT, which causes -Wformat failure on our
+    # intentional use of virReportError(code, NULL).
     gl_WARN_ADD([-Wno-format-nonliteral])
+    if test $lv_cv_gcc_pragma_push_works = no; then
+      gl_WARN_ADD([-Wno-format])
+    fi

     # This should be < 256 really. Currently we're down to 4096,
     # but using 1024 bytes sized buffers (mostly for virStrerror)
diff --git a/src/internal.h b/src/internal.h
index 832a931..02fdb8d 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -151,9 +151,11 @@
  */
 #  ifndef ATTRIBUTE_FMT_PRINTF
 #   if __GNUC_PREREQ (4, 4)
-#    define ATTRIBUTE_FMT_PRINTF(fmtpos,argpos) __attribute__((__format__ (gnu_printf, fmtpos,argpos)))
+#    define ATTRIBUTE_FMT_PRINTF(fmtpos,argpos) \
+    __attribute__((__format__ (__gnu_printf__, fmtpos, argpos)))
 #   else
-#    define ATTRIBUTE_FMT_PRINTF(fmtpos,argpos) __attribute__((__format__ (printf, fmtpos,argpos)))
+#    define ATTRIBUTE_FMT_PRINTF(fmtpos,argpos) \
+    __attribute__((__format__ (__printf__, fmtpos, argpos)))
 #   endif
 #  endif

-- 
1.7.11.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]