Ever since commit eefb881, ATTRIBUTE_NONNULL has been a no-op under
gcc (since it tends to cause more bugs than it cures given gcc's
current lame implementation of the macro). However, the macro is
still useful to Coverity and other static-analysis tools, but only
if we use it correctly. Gcc (and thus Coverity) accepts function
declarations with attributes at the end, but function bodies must
attach attributes to the return type. That is, these are valid:
void foo(void *arg) ATTRIBUTE_NONNULL(1);
void ATTRIBUTE_NONNULL(1) foo(void *arg);
void ATTRIBUTE_NONNULL(1) foo(void *arg) {}
but this is not:
void foo(void *arg) ATTRIBUTE_NONNULL(1) {}
Bug introduced in commit 80533ca, with these symptoms:
nodeinfo.c:206: error: expected ',' or ';' before '{' token
cc1: warning: unrecognized command line option "-Wno-suggest-attribute=const"
cc1: warning: unrecognized command line option "-Wno-suggest-attribute=pure"
make[3]: *** [libvirt_driver_la-nodeinfo.lo] Error 1
* src/nodeinfo.c (virNodeParseNode): Fix syntax error when
non-null attribute is in use.
---
Pushing under the build-breaker rule.
src/nodeinfo.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index d8b71dd..35c5f96 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -202,9 +202,9 @@ CPU_COUNT(cpu_set_t *set)
/* parses a node entry, returning number of processors in the node and
* filling arguments */
static int
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
+ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
virNodeParseNode(const char *node, int *sockets, int *cores, int *threads)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
- ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
{
int ret = -1;
int processors = 0;
--
1.7.11.7
Show replies by date