Commit ff679414 authored by Simon Ruderich's avatar Simon Ruderich
Browse files

slsm: tree: fix incorrect usage of va_start()/va_end()

parent 50126302
......@@ -198,11 +198,16 @@ int slsm_str_append(struct slsm_str *buf, const char *fmt, ...) {
va_list args;
int written;
va_start(args, fmt);
while ((written = vsnprintf(buf->buf + buf->used, buf->size - buf->used, fmt, args) + 1)
> buf->size - buf->used) {
while (1) {
char *new_buf;
size_t new_size = buf->size * 2;
va_start(args, fmt); // must call va_start per loop iteration
written = vsnprintf(buf->buf + buf->used, buf->size - buf->used, fmt, args) + 1;
if (written <= buf->size - buf->used)
break;
va_end(args);
if (new_size > (ssize_t)new_size)
return -EFBIG;
......@@ -213,7 +218,6 @@ int slsm_str_append(struct slsm_str *buf, const char *fmt, ...) {
buf->buf = new_buf;
buf->size = new_size;
}
va_end(args);
buf->used += (size_t)written;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment