mirror of https://git.kore.io/kore.git
Attempt vsnprintf() up to BUFSIZ in kore_buf_appendv().
If the result was too large fall back to vasprintf instead.
This commit is contained in:
parent
0542d70a71
commit
fa69f2a49c
11
src/buf.c
11
src/buf.c
|
@ -56,13 +56,22 @@ void
|
||||||
kore_buf_appendv(struct kore_buf *buf, const char *fmt, va_list args)
|
kore_buf_appendv(struct kore_buf *buf, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
char *b;
|
char *b, sb[BUFSIZ];
|
||||||
|
|
||||||
|
l = vsnprintf(sb, sizeof(sb), fmt, args);
|
||||||
|
if (l == -1)
|
||||||
|
fatal("kore_buf_appendv(): vsnprintf error");
|
||||||
|
|
||||||
|
if ((size_t)l >= sizeof(sb)) {
|
||||||
l = vasprintf(&b, fmt, args);
|
l = vasprintf(&b, fmt, args);
|
||||||
if (l == -1)
|
if (l == -1)
|
||||||
fatal("kore_buf_appendv(): error or truncation");
|
fatal("kore_buf_appendv(): error or truncation");
|
||||||
|
} else {
|
||||||
|
b = sb;
|
||||||
|
}
|
||||||
|
|
||||||
kore_buf_append(buf, (u_int8_t *)b, l);
|
kore_buf_append(buf, (u_int8_t *)b, l);
|
||||||
|
if (b != sb)
|
||||||
free(b);
|
free(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue