Replace non-portable asprintf by g_strdup_printf

g_strdup_printf already handles OOM errors, so some error handling in
QEMU code can be removed.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Stefan Weil 2013-01-16 18:37:23 +01:00 committed by Blue Swirl
parent 0e7a759293
commit e4ada48242
3 changed files with 9 additions and 17 deletions

8
exec.c
View File

@ -863,18 +863,16 @@ static void *file_ram_alloc(RAMBlock *block,
return NULL; return NULL;
} }
if (asprintf(&filename, "%s/qemu_back_mem.XXXXXX", path) == -1) { filename = g_strdup_printf("%s/qemu_back_mem.XXXXXX", path);
return NULL;
}
fd = mkstemp(filename); fd = mkstemp(filename);
if (fd < 0) { if (fd < 0) {
perror("unable to create backing store for hugepages"); perror("unable to create backing store for hugepages");
free(filename); g_free(filename);
return NULL; return NULL;
} }
unlink(filename); unlink(filename);
free(filename); g_free(filename);
memory = (memory+hpagesize-1) & ~(hpagesize-1); memory = (memory+hpagesize-1) & ~(hpagesize-1);

View File

@ -939,14 +939,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data; mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
if (asprintf(&info->value->hardware_address, info->value->hardware_address =
"%02x:%02x:%02x:%02x:%02x:%02x", g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x",
(int) mac_addr[0], (int) mac_addr[1], (int) mac_addr[0], (int) mac_addr[1],
(int) mac_addr[2], (int) mac_addr[3], (int) mac_addr[2], (int) mac_addr[3],
(int) mac_addr[4], (int) mac_addr[5]) == -1) { (int) mac_addr[4], (int) mac_addr[5]);
error_setg_errno(errp, errno, "failed to format MAC");
goto error;
}
info->value->has_hardware_address = true; info->value->has_hardware_address = true;
close(sock); close(sock);

View File

@ -47,10 +47,7 @@ static struct pathelem *new_entry(const char *root,
{ {
struct pathelem *new = malloc(sizeof(*new)); struct pathelem *new = malloc(sizeof(*new));
new->name = strdup(name); new->name = strdup(name);
if (asprintf(&new->pathname, "%s/%s", root, name) == -1) { new->pathname = g_strdup_printf("%s/%s", root, name);
printf("Cannot allocate memory\n");
exit(1);
}
new->num_entries = 0; new->num_entries = 0;
return new; return new;
} }