mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
fixed invalid vasnprintf() calls
This commit is contained in:
@@ -19,6 +19,8 @@
|
|||||||
You can contact me by mail: <tom AT vondein DOT org>.
|
You can contact me by mail: <tom AT vondein DOT org>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE /* vasprintf() linux */
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
void buffer_init(Buffer *b, size_t blocksize, char *name) {
|
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;
|
va_list ap;
|
||||||
char *dst;
|
char *dst;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vasprintf(&dst, fmt, ap);
|
if(vasprintf(&dst, fmt, ap) >= 0) {
|
||||||
|
if(b->end > 0)
|
||||||
|
b->end--;
|
||||||
|
buffer_add(b, dst, strlen(dst)+1);
|
||||||
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if(b->end > 0)
|
|
||||||
b->end--;
|
|
||||||
buffer_add(b, dst, strlen(dst)+1);
|
|
||||||
free(dst);
|
free(dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,12 @@
|
|||||||
You can contact me by mail: <tlinden AT cpan DOT org>.
|
You can contact me by mail: <tlinden AT cpan DOT org>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE /* vasprintf() linux */
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -38,11 +40,14 @@ void fatal(const char * fmt, ...) {
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
||||||
vasprintf(&PCP_ERR, fmt, ap);
|
if(vasprintf(&PCP_ERR, fmt, ap) >= 0) {
|
||||||
|
va_end(ap);
|
||||||
va_end(ap);
|
PCP_ERRSET = 1;
|
||||||
|
}
|
||||||
PCP_ERRSET = 1;
|
else {
|
||||||
|
fprintf(stderr, "Could not store fatal error message %s!\n", fmt);
|
||||||
|
PCP_ERRSET = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fatals_reset() {
|
void fatals_reset() {
|
||||||
@@ -51,7 +56,7 @@ void fatals_reset() {
|
|||||||
|
|
||||||
void fatals_ifany() {
|
void fatals_ifany() {
|
||||||
if(PCP_ERRSET == 1) {
|
if(PCP_ERRSET == 1) {
|
||||||
fprintf(stderr, PCP_ERR);
|
fprintf(stderr, "%s", PCP_ERR);
|
||||||
if(errno) {
|
if(errno) {
|
||||||
fprintf(stderr, "Error: %s\n", strerror(errno));
|
fprintf(stderr, "Error: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
You can contact me by mail: <tom AT vondein DOT org>.
|
You can contact me by mail: <tom AT vondein DOT org>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE /* vasprintf() linux */
|
||||||
#include "pcpstream.h"
|
#include "pcpstream.h"
|
||||||
|
|
||||||
Pcpstream *ps_init(void) {
|
Pcpstream *ps_init(void) {
|
||||||
@@ -618,17 +619,22 @@ size_t ps_print(Pcpstream *stream, const char * fmt, ...) {
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
char *dst;
|
char *dst;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vasprintf(&dst, fmt, ap);
|
if(vasprintf(&dst, fmt, ap) >= 0) {
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
size_t len = strlen(dst);
|
size_t len = strlen(dst);
|
||||||
|
|
||||||
if(stream->is_buffer) {
|
if(stream->is_buffer) {
|
||||||
buffer_add(stream->b, dst, len);
|
buffer_add(stream->b, dst, len);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
len = ps_write(stream, dst, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(dst);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
else {
|
va_end(ap);
|
||||||
return ps_write(stream, dst, len);
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ps_close(Pcpstream *stream) {
|
void ps_close(Pcpstream *stream) {
|
||||||
|
|||||||
Reference in New Issue
Block a user