fixed invalid vasnprintf() calls

This commit is contained in:
git@daemon.de
2014-03-10 17:00:31 +01:00
parent 770d464dd1
commit c3070242a8
3 changed files with 32 additions and 18 deletions

View File

@@ -19,6 +19,7 @@
You can contact me by mail: <tom AT vondein DOT org>.
*/
#define _GNU_SOURCE /* vasprintf() linux */
#include "pcpstream.h"
Pcpstream *ps_init(void) {
@@ -618,17 +619,22 @@ size_t ps_print(Pcpstream *stream, const char * fmt, ...) {
va_list ap;
char *dst;
va_start(ap, fmt);
vasprintf(&dst, fmt, ap);
va_end(ap);
size_t len = strlen(dst);
if(vasprintf(&dst, fmt, ap) >= 0) {
va_end(ap);
size_t len = strlen(dst);
if(stream->is_buffer) {
buffer_add(stream->b, dst, len);
if(stream->is_buffer) {
buffer_add(stream->b, dst, len);
}
else {
len = ps_write(stream, dst, len);
}
free(dst);
return len;
}
else {
return ps_write(stream, dst, len);
}
va_end(ap);
return 0;
}
void ps_close(Pcpstream *stream) {