From 4d713eabf56812a0119c844b8846e5007b2e4918 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 15 Jan 2009 17:54:20 +0000 Subject: [PATCH] Avoid passing NULL to printf %s specifier --- ChangeLog | 5 +++++ src/internal.h | 8 ++++++++ src/libvirt.c | 10 +++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee1052da17..f244064d7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jan 15 17:29:19 GMT 2009 John Levon + + * src/internal.h: + * src/libvirt.c: Avoid passing NULL to printf %s specifier + Thu Jan 15 15:11:35 GMT 2009 John Levon * src/xend_internal.c: Improve xend_get error message 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 #include +#include #ifdef HAVE_SYS_SYSLIMITS_H #include @@ -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); }