PATCH: Replace asprintf() with snprintf() in vnc.c
As previously discussed, this patch removes the non-portable use of asprintf(), replacing it with malloc+snprintf instead
Signed-off-by Daniel P. Berrange <[email protected]>
Daniel
vnc.c +7 -2
@@ -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; }
Signature · 4 lines
|: 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 :|
Hi,
now vnc.c compiles nicely on Solaris as well...
Regard
Palle
Quoted 49 lines · Daniel P. Berrange
Date: Wed, 11 Mar 2009 14:55:06 +0000
From: Daniel P. Berrange <[email protected]>
To: [email protected]
Subject: [Qemu-devel] PATCH: Replaceasprintf()withsnprintf()invnc.cAs previously discussed, this patch removes the non-portable use of
asprintf(), replacing it with malloc+snprintf insteadSigned-off-by Daniel P. Berrange <[email protected]>Daniel
Index:
vnc.c
===================================================================vnc.c +7
-2@@ -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; }Signature · 5 lines
-- |: 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 :|
Anthony Liguori
AppliedQuoted 6 lines · Daniel P. Berrange
As previously discussed, this patch removes the non-portable use of
asprintf(), replacing it with malloc+snprintf insteadSigned-off-by Daniel P. Berrange <[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori