use vasprintf() in cstp_printf()

This commit is contained in:
Nikos Mavrogiannopoulos
2015-02-19 11:47:20 +01:00
parent 11f43f144a
commit 41a6c25a91
+12 -7
View File
@@ -26,6 +26,9 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#ifndef _GNU_SOURCE
# define _GNU_SOURCE /* for vasprintf() */
#endif
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@@ -198,17 +201,19 @@ unsigned tls_has_session_cert(struct worker_st * ws)
int __attribute__ ((format(printf, 2, 3))) int __attribute__ ((format(printf, 2, 3)))
cstp_printf(worker_st *ws, const char *fmt, ...) cstp_printf(worker_st *ws, const char *fmt, ...)
{ {
char buf[1024]; char *buf;
va_list args; va_list args;
size_t s; int ret, s;
buf[1023] = 0;
va_start(args, fmt); va_start(args, fmt);
s = vsnprintf(buf, 1023, fmt, args); s = vasprintf(&buf, fmt, args);
va_end(args); if (s == -1)
return cstp_send(ws, buf, s); return -1;
va_end(args);
ret = cstp_send(ws, buf, s);
free(buf);
return ret;
} }
void cstp_close(worker_st *ws) void cstp_close(worker_st *ws)