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
17
src/buf.c
17
src/buf.c
|
@ -56,14 +56,23 @@ void
|
|||
kore_buf_appendv(struct kore_buf *buf, const char *fmt, va_list args)
|
||||
{
|
||||
int l;
|
||||
char *b;
|
||||
char *b, sb[BUFSIZ];
|
||||
|
||||
l = vasprintf(&b, fmt, args);
|
||||
l = vsnprintf(sb, sizeof(sb), fmt, args);
|
||||
if (l == -1)
|
||||
fatal("kore_buf_appendv(): error or truncation");
|
||||
fatal("kore_buf_appendv(): vsnprintf error");
|
||||
|
||||
if ((size_t)l >= sizeof(sb)) {
|
||||
l = vasprintf(&b, fmt, args);
|
||||
if (l == -1)
|
||||
fatal("kore_buf_appendv(): error or truncation");
|
||||
} else {
|
||||
b = sb;
|
||||
}
|
||||
|
||||
kore_buf_append(buf, (u_int8_t *)b, l);
|
||||
free(b);
|
||||
if (b != sb)
|
||||
free(b);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue