]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Avoid passing NULL to printf %s specifier
authorJohn Levon <john.levon@sun.com>
Thu, 15 Jan 2009 17:54:20 +0000 (17:54 +0000)
committerJohn Levon <john.levon@sun.com>
Thu, 15 Jan 2009 17:54:20 +0000 (17:54 +0000)
ChangeLog
src/internal.h
src/libvirt.c

index ee1052da17be8e4513d969d738e83b507efb3032..f244064d7f3976b65ed3a9bbed0198e0618f266b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Jan 15 17:29:19 GMT 2009  John Levon  <levon@movementarian.org>
+
+       * src/internal.h:
+       * src/libvirt.c: Avoid passing NULL to printf %s specifier
+
 Thu Jan 15 15:11:35 GMT 2009  John Levon  <levon@movementarian.org>
 
        * src/xend_internal.c: Improve xend_get error message
index f0c3d7dd1346197fbddb2688043c7463b741155d..696e5db1a38645d2fedcd65b128685c9c7956556 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <errno.h>
 #include <limits.h>
+#include <verify.h>
 
 #ifdef HAVE_SYS_SYSLIMITS_H
 #include <sys/syslimits.h>
 #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:
  *
index 37eaa63a3e083c14736b70608634644cc34a7fad..a96eecd40bee162fdc5a4d193cc39dbf52da95ca 100644 (file)
@@ -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);
 }