From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] PATCH: Replace asprintf() with snprintf() in vnc.c
Date: Wed, 11 Mar 2009 14:55:06 +0000 [thread overview]
Message-ID: <20090311145506.GM23995@redhat.com> (raw)
As previously discussed, this patch removes the non-portable use of
asprintf(), replacing it with malloc+snprintf instead
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Daniel
Index: vnc.c
===================================================================
--- vnc.c (revision 6811)
+++ vnc.c (working copy)
@@ -53,6 +53,7 @@
char host[NI_MAXHOST];
char serv[NI_MAXSERV];
int err;
+ size_t addrlen;
if ((err = getnameinfo((struct sockaddr *)sa, salen,
host, sizeof(host),
@@ -63,8 +64,12 @@
return NULL;
}
- if (asprintf(&addr, format, host, serv) < 0)
- return NULL;
+ /* Enough for the existing format + the 2 vars we're
+ * subsituting in. */
+ addrlen = strlen(format) + strlen(host) + strlen(serv);
+ addr = qemu_malloc(addrlen + 1);
+ snprintf(addr, addrlen, format, host, serv);
+ addr[addrlen] = '\0';
return addr;
}
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
next reply other threads:[~2009-03-11 14:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-11 14:55 Daniel P. Berrange [this message]
2009-03-11 20:15 ` [Qemu-devel] PATCH: Replace asprintf() with snprintf() in vnc.c Palle Lyckegaard
2009-03-13 15:31 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090311145506.GM23995@redhat.com \
--to=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).