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,8 @@
You can contact me by mail: <tom AT vondein DOT org>.
*/
#define _GNU_SOURCE /* vasprintf() linux */
#include "buffer.h"
void buffer_init(Buffer *b, size_t blocksize, char *name) {
@@ -88,11 +90,12 @@ void buffer_add_str(Buffer *b, const char * fmt, ...) {
va_list ap;
char *dst;
va_start(ap, fmt);
vasprintf(&dst, fmt, ap);
va_end(ap);
if(vasprintf(&dst, fmt, ap) >= 0) {
if(b->end > 0)
b->end--;
buffer_add(b, dst, strlen(dst)+1);
}
va_end(ap);
free(dst);
}

View File

@@ -19,10 +19,12 @@
You can contact me by mail: <tlinden AT cpan DOT org>.
*/
#define _GNU_SOURCE /* vasprintf() linux */
#include "defines.h"
#include "platform.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
@@ -38,12 +40,15 @@ void fatal(const char * fmt, ...) {
va_list ap;
va_start(ap, fmt);
vasprintf(&PCP_ERR, fmt, ap);
if(vasprintf(&PCP_ERR, fmt, ap) >= 0) {
va_end(ap);
PCP_ERRSET = 1;
}
else {
fprintf(stderr, "Could not store fatal error message %s!\n", fmt);
PCP_ERRSET = 1;
}
}
void fatals_reset() {
PCP_ERRSET = 0;
@@ -51,7 +56,7 @@ void fatals_reset() {
void fatals_ifany() {
if(PCP_ERRSET == 1) {
fprintf(stderr, PCP_ERR);
fprintf(stderr, "%s", PCP_ERR);
if(errno) {
fprintf(stderr, "Error: %s\n", strerror(errno));
}

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);
if(vasprintf(&dst, fmt, ap) >= 0) {
va_end(ap);
size_t len = strlen(dst);
if(stream->is_buffer) {
buffer_add(stream->b, dst, len);
return len;
}
else {
return ps_write(stream, dst, len);
len = ps_write(stream, dst, len);
}
free(dst);
return len;
}
va_end(ap);
return 0;
}
void ps_close(Pcpstream *stream) {