path: root/compat/snprintf.c
AgeCommit message (Collapse)Author
2016-03-30MSVC: vsnprintf in Visual Studio 2015 doesn't need SNPRINTF_SIZE_CORR any moreSven Strickroth
In MSVC2015 the behavior of vsnprintf was changed. W/o this fix there is one character missing at the end. Signed-off-by: Sven Strickroth <> Acked-by: Johannes Schindelin <> Acked-by: Sebastian Schuberth <> Signed-off-by: Junio C Hamano <>
2011-12-12compat/snprintf: don't look at va_list twiceJeff King
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 <> Signed-off-by: Junio C Hamano <>
2009-09-19Test for WIN32 instead of __MINGW32_Frank Li
The code which is conditional on MinGW32 is actually conditional on Windows. Use the WIN32 symbol, which is defined by the MINGW32 and MSVC environments, but not by Cygwin. Define SNPRINTF_SIZE_CORR=1 for MSVC too, as its vsnprintf function does not add NUL at the end of the buffer if the result fits the buffer size exactly. Signed-off-by: Frank Li <> Signed-off-by: Marius Storm-Olsen <> Acked-by: Johannes Sixt <> Signed-off-by: Junio C Hamano <>
2009-08-22compat/snprintf.c: clarify SNPRINTF_SIZE_CORRJunio C Hamano
Signed-off-by: Junio C Hamano <>
2009-06-01MinGW: GCC >= 4 does not need SNPRINTF_SIZE_CORR anymoreJohannes Schindelin
Signed-off-by: Johannes Schindelin <> Signed-off-by: Steffen Prohaska <> Signed-off-by: Junio C Hamano <>
2008-08-21compat/snprintf.c: handle snprintf's that always return the # chars transmittedBrandon Casey
Some platforms provide a horribly broken snprintf. More broken than the platforms that return -1 when there is too little space in the target buffer for the formatted string. Some platforms provide an snprintf which _always_ returns the number of characters transmitted to the buffer, regardless of whether there was enough space or not. IRIX 6.5 is such a platform. IRIX does have a working snprintf(), but it is only provided when _NO_XOPEN5 evaluates to zero, and this only happens if _XOPEN_SOURCE is defined, but definition of _XOPEN_SOURCE prevents inclusion of many other common functions and defines. So it must be avoided. Work around these horribly broken snprintf implementations by detecting an snprintf call which results in the number of transmitted characters exactly equal to the length of our buffer and retrying with a larger buffer just to be safe. Signed-off-by: Brandon Casey <> Acked-by: Johannes Sixt <> Signed-off-by: Junio C Hamano <>
2008-06-22Add target architecture MinGW.Johannes Sixt
With this change GIT can be compiled and linked using MinGW. Builtins that only read the repository such as the log family and grep already work. Simple stubs are provided for a number of functions that the Windows C runtime does not offer. They will be completed in later patches. However, a fix for the snprintf/vsnprintf replacement is applied here to avoid buffer overflows. Dmitry Kakurin pointed out that access(..., X_OK) would always fails on Vista and suggested the -D__USE_MINGW_ACCESS workaround. Signed-off-by: Johannes Sixt <>
2008-03-05Add compat/snprintf.c for systems that return bogusMichal Rokos
Some systems (namely HPUX and Windows) return -1 when maxsize in snprintf() and in vsnprintf() is reached. So replace snprintf() and vsnprintf() functions with our own ones that return correct value upon overflow. [jc: verified that review comments by J6t have been incorporated, and tightened the check to verify the resulting buffer contents, suggested by Wayne Davison] Signed-off-by: Michal Rokos <> Signed-off-by: Junio C Hamano <>