Commit 457772e68f83ea02a33b58a70bd25ec5c028c077

Authored by aliguori
1 parent 5b0d2727

Replace asprintf() with snprintf() in vnc.c ("Daniel P. Berrange")

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>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6843 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 7 additions and 2 deletions
... ... @@ -53,6 +53,7 @@ static char *addr_to_string(const char *format,
53 53 char host[NI_MAXHOST];
54 54 char serv[NI_MAXSERV];
55 55 int err;
  56 + size_t addrlen;
56 57  
57 58 if ((err = getnameinfo((struct sockaddr *)sa, salen,
58 59 host, sizeof(host),
... ... @@ -63,8 +64,12 @@ static char *addr_to_string(const char *format,
63 64 return NULL;
64 65 }
65 66  
66   - if (asprintf(&addr, format, host, serv) < 0)
67   - return NULL;
  67 + /* Enough for the existing format + the 2 vars we're
  68 + * subsituting in. */
  69 + addrlen = strlen(format) + strlen(host) + strlen(serv);
  70 + addr = qemu_malloc(addrlen + 1);
  71 + snprintf(addr, addrlen, format, host, serv);
  72 + addr[addrlen] = '\0';
68 73  
69 74 return addr;
70 75 }
... ...