]> git.ipfire.org Git - thirdparty/git.git/commit - progress.c
progress: store throughput display in a strbuf
authorJeff King <peff@peff.net>
Thu, 24 Sep 2015 21:05:57 +0000 (17:05 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 25 Sep 2015 17:18:18 +0000 (10:18 -0700)
commit3131977de1476185209d4d56a0494f5b30ee5557
treec78667db915c3fcb1add2b73c20fcc6e47a6a90f
parent0bb443fdd2518600f88434e2aad8f515546ee707
progress: store throughput display in a strbuf

Coverity noticed that we strncpy() into a fixed-size buffer
without making sure that it actually ended up
NUL-terminated. This is unlikely to be a bug in practice,
since throughput strings rarely hit 32 characters, but it
would be nice to clean it up.

The most obvious way to do so is to add a NUL-terminator.
But instead, this patch switches the fixed-size buffer out
for a strbuf. At first glance this seems much less
efficient, until we realize that filling in the fixed-size
buffer is done by writing into a strbuf and copying the
result!

By writing straight to the buffer, we actually end up more
efficient:

  1. We avoid an extra copy of the bytes.

  2. Rather than malloc/free each time progress is shown, we
     can strbuf_reset and use the same buffer each time.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
progress.c