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 <michal.rokos@nextsoft.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b9217642ef
commit
c4582f93a2
@ -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
|
||||
|
Reference in New Issue
Block a user