Re: [libvirt] [PATCH 5/5] read saved vm status on libvirtd startup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 12, 2008 at 08:30:26PM +0000, Daniel P. Berrange wrote:
> This is crying out for us to write a virASprintf() that explicitly
> always sets path = NULL upon failure. And then blacklist 'asprintf'
> in make syntax-check.
Possible virAsprintf attached. I've already moved the posted patch
series over to it. I'll blacklist it once this is in and we have more
calles moved over. O.k.?
Cheers,
 -- Guido
>From 31b6bf2199b42f40dd138971802d6afa94f59acf Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@xxxxxxxxxxx>
Date: Fri, 12 Dec 2008 22:18:07 +0100
Subject: [PATCH] safe virAsprintf

---
 src/libvirt_sym.version.in |    1 +
 src/util.c                 |   20 ++++++++++++++++++++
 src/util.h                 |    1 +
 3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/libvirt_sym.version.in b/src/libvirt_sym.version.in
index de0bc4a..684be01 100644
--- a/src/libvirt_sym.version.in
+++ b/src/libvirt_sym.version.in
@@ -595,6 +595,7 @@ LIBVIRT_PRIVATE_@VERSION@ {
 	virFileReadPid;
 	virFileLinkPointsTo;
 	virParseNumber;
+	virAsprintf;
 	virRun;
 	virSkipSpaces;
 
diff --git a/src/util.c b/src/util.c
index da26009..820d11c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1153,6 +1153,26 @@ virParseNumber(const char **str)
     return (ret);
 }
 
+/**
+ * virAsprintf
+ *
+ * like asprintf but makes sure *strp == NULL on failure
+ */
+int 
+virAsprintf(char **strp, const char *fmt, ...)
+{
+    va_list ap;
+    int ret;
+
+    va_start(ap, fmt);
+
+    if ((ret = vasprintf(strp, fmt, ap)) == -1)
+        *strp = NULL;
+
+    va_end(ap);
+    return ret;
+}
+
 /* Compare two MAC addresses, ignoring differences in case,
  * as well as leading zeros.
  */
diff --git a/src/util.h b/src/util.h
index 0748cbf..3d603dc 100644
--- a/src/util.h
+++ b/src/util.h
@@ -112,6 +112,7 @@ int virMacAddrCompare (const char *mac1, const char *mac2);
 
 void virSkipSpaces(const char **str);
 int virParseNumber(const char **str);
+int virAsprintf(char **strp, const char *fmt, ...);
 
 #define VIR_MAC_BUFLEN 6
 #define VIR_MAC_PREFIX_BUFLEN 3
-- 
1.6.0.2

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]