summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Levon <john.levon@sun.com>2009-01-15 17:54:20 +0000
committerJohn Levon <john.levon@sun.com>2009-01-15 17:54:20 +0000
commit4d713eabf56812a0119c844b8846e5007b2e4918 (patch)
tree5465e62571f1bb429c3481f74f3cf23c36bd8740 /src
parentc7095a4b4c21b0e919ec926ddf80b0bebdc8ec4e (diff)
downloadlibvirt-4d713eabf56812a0119c844b8846e5007b2e4918.tar.gz
Avoid passing NULL to printf %s specifier
Diffstat (limited to 'src')
-rw-r--r--src/internal.h8
-rw-r--r--src/libvirt.c10
2 files changed, 13 insertions, 5 deletions
diff --git a/src/internal.h b/src/internal.h
index f0c3d7dd13..696e5db1a3 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -7,6 +7,7 @@
#include <errno.h>
#include <limits.h>
+#include <verify.h>
#ifdef HAVE_SYS_SYSLIMITS_H
#include <sys/syslimits.h>
@@ -115,6 +116,13 @@
#define ATTRIBUTE_RETURN_CHECK
#endif /* __GNUC__ */
+/*
+ * Use this when passing possibly-NULL strings to printf-a-likes.
+ */
+#define NULLSTR(s) \
+ ((void)verify_true(sizeof *(s) == sizeof (char)), \
+ (s) ? (s) : "(null)")
+
/**
* TODO:
*
diff --git a/src/libvirt.c b/src/libvirt.c
index 37eaa63a3e..a96eecd40b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -852,10 +852,10 @@ do_open (const char *name,
" port %d\n"
" path %s\n",
name,
- ret->uri->scheme, ret->uri->opaque,
- ret->uri->authority, ret->uri->server,
- ret->uri->user, ret->uri->port,
- ret->uri->path);
+ NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->opaque),
+ NULLSTR(ret->uri->authority), NULLSTR(ret->uri->server),
+ NULLSTR(ret->uri->user), ret->uri->port,
+ NULLSTR(ret->uri->path));
} else {
DEBUG0("no name, allowing driver auto-select");
}
@@ -1044,7 +1044,7 @@ virConnectOpenAuth(const char *name,
if (virInitialize() < 0)
return NULL;
- DEBUG("name=%s, auth=%p, flags=%d", name, auth, flags);
+ DEBUG("name=%s, auth=%p, flags=%d", NULLSTR(name), auth, flags);
return do_open (name, auth, flags);
}