Skip to content
  • Jeff King's avatar
    compat/snprintf: don't look at va_list twice · a9bfbc5b
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    If you define SNPRINTF_RETURNS_BOGUS, we use a special
    git_vsnprintf wrapper assumes that vsnprintf returns "-1"
    instead of the number of characters that you would need to
    store the result.
    
    To do this, it invokes vsnprintf multiple times, growing a
    heap buffer until we have enough space to hold the result.
    However, this means we evaluate the va_list parameter
    multiple times, which is generally a bad thing (it may be
    modified by calls to vsnprintf, yielding undefined
    behavior).
    
    Instead, we must va_copy it and hand the copy to vsnprintf,
    so we always have a pristine va_list.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    a9bfbc5b