filebuf: Fix printf buffer overflows The filebuf was not being properly written after a flush. This should cut it now. Fixes #228
diff --git a/src/filebuf.c b/src/filebuf.c
index 97dec83..d0579b1 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -363,14 +363,19 @@ int git_filebuf_printf(git_filebuf *file, const char *format, ...)
int len, error;
va_start(arglist, format);
-
len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
+ va_end(arglist);
if (len < 0 || (size_t)len >= space_left) {
if ((error = flush_buffer(file)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to output to buffer");
+ space_left = file->buf_size - file->buf_pos;
+
+ va_start(arglist, format);
len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
+ va_end(arglist);
+
if (len < 0 || (size_t)len > file->buf_size)
return GIT_ENOMEM;
}