Skip to content
  • Jeff King's avatar
    strbuf: make strbuf_addftime more robust · e4f031e3
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    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: default avatarEric Sunshine <sunshine@sunshineco.com>
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    e4f031e3