From: Peter Verthez Date: Sat, 28 Sep 2002 17:54:41 +0000 (+0000) Subject: Portability: have fallback solution if vsnprintf is not available. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=202b56b1c003d16d7a68efcbff3e372ac7db8d5f;p=gedcom-parse.git Portability: have fallback solution if vsnprintf is not available. --- diff --git a/gedcom/message.c b/gedcom/message.c index 213e049..5f0bdc3 100644 --- a/gedcom/message.c +++ b/gedcom/message.c @@ -24,7 +24,13 @@ #include "gedcom_internal.h" #include "gedcom.h" +#if HAVE_VSNPRINTF #define INITIAL_BUF_SIZE 256 +#else +/* Risk on overflowing buffer, so make size big */ +#define INITIAL_BUF_SIZE 65536 +#endif + char *mess_buffer = NULL; size_t bufsize; @@ -76,6 +82,7 @@ int safe_buf_vappend(const char *s, va_list ap) char *buf_ptr = mess_buffer + len; int rest_size = bufsize - len; +#if HAVE_VSNPRINTF res = vsnprintf(buf_ptr, rest_size, s, ap); if (res > -1 && res < rest_size) { @@ -85,6 +92,15 @@ int safe_buf_vappend(const char *s, va_list ap) bufsize *= 2; mess_buffer = realloc(mess_buffer, bufsize); } +#else /* not HAVE_VSNPRINTF */ +# if HAVE_VSPRINTF +# warning "Using VSPRINTF. Buffer overflow could happen!" + vsprintf(buf_ptr, s, ap); + break; +# else /* not HAVE_VPRINTF */ +# error "Your standard library has neither vsnprintf nor vsprintf defined. One of them is required!" +# endif +#endif } } return res;