author | Jeff King <peff@peff.net> | |
Mon, 12 Dec 2011 14:25:51 +0000 (09:25 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 12 Dec 2011 17:09:35 +0000 (09:09 -0800) | ||
commit | a9bfbc5b698103b1553e1023c4f77001cc861e79 | |
tree | c7357e4a4a70b5fc712770da1461717d4c395d06 | tree | snapshot |
parent | 26db0f2e3afc043e184a5e0ce5eb7c53aeb1f644 | commit | diff |
compat/snprintf: don't look at va_list twice
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: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/snprintf.c | diff | blob | history |