qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] PATCH: Replace asprintf() with snprintf() in vnc.c
@ 2009-03-11 14:55 Daniel P. Berrange
  2009-03-11 20:15 ` Palle Lyckegaard
  2009-03-13 15:31 ` Anthony Liguori
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel P. Berrange @ 2009-03-11 14:55 UTC (permalink / raw)
  To: qemu-devel

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 :|

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-13 15:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-11 14:55 [Qemu-devel] PATCH: Replace asprintf() with snprintf() in vnc.c Daniel P. Berrange
2009-03-11 20:15 ` Palle Lyckegaard
2009-03-13 15:31 ` Anthony Liguori

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).