* [Qemu-devel] [PATCH] Replace non-portable asprintf by g_strdup_printf
@ 2013-01-16 17:37 Stefan Weil
2013-01-19 14:00 ` Blue Swirl
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil @ 2013-01-16 17:37 UTC (permalink / raw)
To: qemu-devel; +Cc: Stefan Weil
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>
---
TODO:
* hardware_address is set, but obviously never used.
* pathname has no free / g_free.
Regards,
Stefan Weil
exec.c | 8 +++-----
qga/commands-posix.c | 13 +++++--------
util/path.c | 5 +----
3 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/exec.c b/exec.c
index 5689613..b85508b 100644
--- a/exec.c
+++ b/exec.c
@@ -863,18 +863,16 @@ static void *file_ram_alloc(RAMBlock *block,
return NULL;
}
- if (asprintf(&filename, "%s/qemu_back_mem.XXXXXX", path) == -1) {
- return NULL;
- }
+ filename = g_strdup_printf("%s/qemu_back_mem.XXXXXX", path);
fd = mkstemp(filename);
if (fd < 0) {
perror("unable to create backing store for hugepages");
- free(filename);
+ g_free(filename);
return NULL;
}
unlink(filename);
- free(filename);
+ g_free(filename);
memory = (memory+hpagesize-1) & ~(hpagesize-1);
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 77f6ee7..0ad73f3 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -939,14 +939,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
- 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->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]);
info->value->has_hardware_address = true;
close(sock);
diff --git a/util/path.c b/util/path.c
index 4c5b0f6..f0c6962 100644
--- a/util/path.c
+++ b/util/path.c
@@ -47,10 +47,7 @@ static struct pathelem *new_entry(const char *root,
{
struct pathelem *new = malloc(sizeof(*new));
new->name = strdup(name);
- if (asprintf(&new->pathname, "%s/%s", root, name) == -1) {
- printf("Cannot allocate memory\n");
- exit(1);
- }
+ new->pathname = g_strdup_printf("%s/%s", root, name);
new->num_entries = 0;
return new;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] Replace non-portable asprintf by g_strdup_printf
2013-01-16 17:37 [Qemu-devel] [PATCH] Replace non-portable asprintf by g_strdup_printf Stefan Weil
@ 2013-01-19 14:00 ` Blue Swirl
0 siblings, 0 replies; 2+ messages in thread
From: Blue Swirl @ 2013-01-19 14:00 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-devel
Thanks, applied. This fixes a warning on mingw32.
On Wed, Jan 16, 2013 at 5:37 PM, Stefan Weil <sw@weilnetz.de> wrote:
> 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>
> ---
>
> TODO:
>
> * hardware_address is set, but obviously never used.
>
> * pathname has no free / g_free.
>
> Regards,
>
> Stefan Weil
>
>
> exec.c | 8 +++-----
> qga/commands-posix.c | 13 +++++--------
> util/path.c | 5 +----
> 3 files changed, 9 insertions(+), 17 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index 5689613..b85508b 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -863,18 +863,16 @@ static void *file_ram_alloc(RAMBlock *block,
> return NULL;
> }
>
> - if (asprintf(&filename, "%s/qemu_back_mem.XXXXXX", path) == -1) {
> - return NULL;
> - }
> + filename = g_strdup_printf("%s/qemu_back_mem.XXXXXX", path);
>
> fd = mkstemp(filename);
> if (fd < 0) {
> perror("unable to create backing store for hugepages");
> - free(filename);
> + g_free(filename);
> return NULL;
> }
> unlink(filename);
> - free(filename);
> + g_free(filename);
>
> memory = (memory+hpagesize-1) & ~(hpagesize-1);
>
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 77f6ee7..0ad73f3 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -939,14 +939,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
>
> mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
>
> - 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->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]);
>
> info->value->has_hardware_address = true;
> close(sock);
> diff --git a/util/path.c b/util/path.c
> index 4c5b0f6..f0c6962 100644
> --- a/util/path.c
> +++ b/util/path.c
> @@ -47,10 +47,7 @@ static struct pathelem *new_entry(const char *root,
> {
> struct pathelem *new = malloc(sizeof(*new));
> new->name = strdup(name);
> - if (asprintf(&new->pathname, "%s/%s", root, name) == -1) {
> - printf("Cannot allocate memory\n");
> - exit(1);
> - }
> + new->pathname = g_strdup_printf("%s/%s", root, name);
> new->num_entries = 0;
> return new;
> }
> --
> 1.7.10.4
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-01-19 14:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-16 17:37 [Qemu-devel] [PATCH] Replace non-portable asprintf by g_strdup_printf Stefan Weil
2013-01-19 14:00 ` Blue Swirl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).