From: "Daniel P. Berrange" <berrange(a)redhat.com>
Import ATTRIBUTE_RETURN_CHECK, ATTRIBUTE_UNUSED &
ATTRIBUTE_NONNULL macros
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
libvirt-utils.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/libvirt-utils.h b/libvirt-utils.h
index 961cc20..f608eb4 100644
--- a/libvirt-utils.h
+++ b/libvirt-utils.h
@@ -54,4 +54,56 @@
# define ignore_value(x) ((void) (x))
# endif
+# ifdef __GNUC__
+/**
+ * ATTRIBUTE_UNUSED:
+ *
+ * Macro to flag consciously unused parameters to functions
+ */
+# ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED __attribute__((__unused__))
+# endif
+
+/* gcc's handling of attribute nonnull is less than stellar - it does
+ * NOT improve diagnostics, and merely allows gcc to optimize away
+ * null code checks even when the caller manages to pass null in spite
+ * of the attribute, leading to weird crashes. Coverity, on the other
+ * hand, knows how to do better static analysis based on knowing
+ * whether a parameter is nonnull. Make this attribute conditional
+ * based on whether we are compiling for real or for analysis, while
+ * still requiring correct gcc syntax when it is turned off. See also
+ *
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17308 */
+# ifndef ATTRIBUTE_NONNULL
+# if __GNUC_PREREQ (3, 3)
+# if STATIC_ANALYSIS
+# define ATTRIBUTE_NONNULL(m) __attribute__((__nonnull__(m)))
+# else
+# define ATTRIBUTE_NONNULL(m) __attribute__(())
+# endif
+# else
+# define ATTRIBUTE_NONNULL(m)
+# endif
+# endif
+
+# ifndef ATTRIBUTE_RETURN_CHECK
+# if __GNUC_PREREQ (3, 4)
+# define ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
+# else
+# define ATTRIBUTE_RETURN_CHECK
+# endif
+# endif
+
+# else
+# ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED
+# endif
+# ifndef ATTRIBUTE_NONNULL
+# define ATTRIBUTE_NONNULL(m)
+# endif
+# ifndef ATTRIBUTE_RETURN_CHECK
+# define ATTRIBUTE_RETURN_CHECK
+# endif
+# endif /* __GNUC__ */
+
+
#endif /* __LIBVIRT_UTILS_H__ */
--
1.8.3.2