Skip to content
  • Jeff King's avatar
    vreportf: avoid intermediate buffer · f4c3edc0
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    When we call "die(fmt, args...)", we end up in vreportf with
    two pieces of information:
    
      1. The prefix "fatal: "
    
      2. The original fmt and va_list of args.
    
    We format item (2) into a temporary buffer, and then fprintf
    the prefix and the temporary buffer, along with a newline.
    This has the unfortunate side effect of truncating any error
    messages that are longer than 4096 bytes.
    
    Instead, let's use separate calls for the prefix and
    newline, letting us hand the item (2) directly to vfprintf.
    This is essentially undoing d048a96e
    
     (print
    warning/error/fatal messages in one shot, 2007-11-09), which
    tried to have the whole output end up in a single `write`
    call.
    
    But we can address this instead by explicitly requesting
    line-buffering for the output handle, and by making sure
    that the buffer is empty before we start (so that outputting
    the prefix does not cause a flush due to hitting the buffer
    limit).
    
    We may still break the output into two writes if the content
    is larger than our buffer, but there's not much we can do
    there; depending on the stdio implementation, that might
    have happened even with a single fprintf call.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    f4c3edc0