]> git.ipfire.org Git - thirdparty/git.git/commit - strbuf.c
strbuf: make strbuf_addftime more robust
authorJeff King <peff@peff.net>
Tue, 30 Jun 2015 13:26:53 +0000 (09:26 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Jul 2015 05:17:06 +0000 (22:17 -0700)
commite4f031e34b08e3217c10942e682920a6939308a0
tree7988cf4a7edab0ed17a16a5be99f1a044821a284
parentaa1462cc3d3b0c4c8ad6a60aaf31e0f3a424162d
strbuf: make strbuf_addftime more robust

The return value of strftime is poorly designed; when it
returns 0, the caller cannot tell if the buffer was not
large enough, or if the output was actually 0 bytes. In the
original implementation of strbuf_addftime, we simply punted
and guessed that our 128-byte hint would be large enough.

We can do better, though, if we're willing to treat strftime
like less of a black box. We can munge the incoming format
to make sure that it never produces 0-length output, and
then "fix" the resulting output.  That lets us reliably grow
the buffer based on strftime's return value.

Clever-idea-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf.c
t/t6300-for-each-ref.sh