From c4582f93a263bea534288e7f7ad8937405964cd4 Mon Sep 17 00:00:00 2001 From: Michal Rokos Date: Wed, 5 Mar 2008 16:46:13 +0100 Subject: Add compat/snprintf.c for systems that return bogus 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 --- git-compat-util.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index 2a40703c85..9d04faefb8 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -209,6 +209,15 @@ void *gitmemmem(const void *haystack, size_t haystacklen, extern FILE *git_fopen(const char*, const char*); #endif +#ifdef SNPRINTF_RETURNS_BOGUS +#define snprintf git_snprintf +extern int git_snprintf(char *str, size_t maxsize, + const char *format, ...); +#define vsnprintf git_vsnprintf +extern int git_vsnprintf(char *str, size_t maxsize, + const char *format, va_list ap); +#endif + #ifdef __GLIBC_PREREQ #if __GLIBC_PREREQ(2, 1) #define HAVE_STRCHRNUL -- cgit v1.2.3