• Jeff King's avatar
    progress: store throughput display in a strbuf · 3131977d
    Jeff King authored
    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
    By writing straight to the buffer, we actually end up more
      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: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
progress.c 6.29 KB