upload-archive: convert sprintf to strbuf

When we report an error to the client, we format it into a fixed-size buffer using vsprintf(). This can't actually overflow in practice, since we only format a very tame subset of strings (mostly strerror() output). However, it's hard to tell immediately, so let's just use a strbuf so readers do not have to wonder. We do add an allocation here, but the performance is not important; the next step is to call die() anyway. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 24, 2015 at 17:07 UTC 0cb9d6d6b63ad7fea4ca8363f7f1f921b1e16ec7
1 file changed +4 -5
builtin/upload-archive.c
+4 -5
@@ -49,15 +49,14 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
49 __attribute__((format (printf, 1, 2)))
50 static void error_clnt(const char *fmt, ...)
51 {
52 - char buf[1024];
52 + struct strbuf buf = STRBUF_INIT;
53 va_list params;
54 - int len;
54
55 va_start(params, fmt);
57 - len = vsprintf(buf, fmt, params);
56 + strbuf_vaddf(&buf, fmt, params);
57 va_end(params);
59 - send_sideband(1, 3, buf, len, LARGE_PACKET_MAX);
60 - die("sent error to the client: %s", buf);
58 + send_sideband(1, 3, buf.buf, buf.len, LARGE_PACKET_MAX);
59 + die("sent error to the client: %s", buf.buf);
60 }
61
62 static ssize_t process_input(int child_fd, int band)