From 0ee5aff0477435353e6da8c924798e48daf1bc34 Mon Sep 17 00:00:00 2001
Message-Id: <0ee5aff0477435353e6da8c924798e48daf1bc34.1367947969.git.minovotn@redhat.com>
In-Reply-To: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com>
References: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com>
From: Michal Novotny <minovotn@redhat.com>
Date: Tue, 7 May 2013 18:36:10 +0200
Subject: [PATCH 006/114] Revert "Replace non-portable asprintf by
 g_strdup_printf"

This reverts commit b65c2ce148339a65790a36b6bb1c8c02d4bfa0a0.

Reverting as asked by Laszlo in message <51892739.2030807@redhat.com>
because of the ordering issue (most likely) related to supersed
testing.

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 exec.c               |  8 +++++---
 path.c               |  5 ++++-
 qga/commands-posix.c | 13 ++++++++-----
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/exec.c b/exec.c
index d8544aa..298d94c 100644
--- a/exec.c
+++ b/exec.c
@@ -2583,16 +2583,18 @@ static void *file_ram_alloc(RAMBlock *block,
         return NULL;
     }
 
-    filename = g_strdup_printf("%s/kvm.XXXXXX", path);
+    if (asprintf(&filename, "%s/kvm.XXXXXX", path) == -1) {
+	return NULL;
+    }
 
     fd = mkstemp(filename);
     if (fd < 0) {
 	perror("mkstemp");
-	g_free(filename);
+	free(filename);
 	return NULL;
     }
     unlink(filename);
-    g_free(filename);
+    free(filename);
 
     memory = (memory+hpagesize-1) & ~(hpagesize-1);
 
diff --git a/path.c b/path.c
index 39edc00..0d2bf14 100644
--- a/path.c
+++ b/path.c
@@ -46,7 +46,10 @@ static struct pathelem *new_entry(const char *root,
 {
     struct pathelem *new = malloc(sizeof(*new));
     new->name = strdup(name);
-    new->pathname = g_strdup_printf("%s/%s", root, name);
+    if (asprintf(&new->pathname, "%s/%s", root, name) == -1) {
+        printf("Cannot allocate memory\n");
+        exit(1);
+    }
     new->num_entries = 0;
     return new;
 }
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 8cdc9c5..e28dfd4 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1016,11 +1016,14 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
 
             mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
 
-            info->value->hardware_address =
-                g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x",
-                                (int) mac_addr[0], (int) mac_addr[1],
-                                (int) mac_addr[2], (int) mac_addr[3],
-                                (int) mac_addr[4], (int) mac_addr[5]);
+            if (asprintf(&info->value->hardware_address,
+                         "%02x:%02x:%02x:%02x:%02x:%02x",
+                         (int) mac_addr[0], (int) mac_addr[1],
+                         (int) mac_addr[2], (int) mac_addr[3],
+                         (int) mac_addr[4], (int) mac_addr[5]) == -1) {
+                error_setg_errno(errp, errno, "failed to format MAC");
+                goto error;
+            }
 
             info->value->has_hardware_address = true;
             close(sock);
-- 
1.7.11.7

