hopefully a more correct implementation

This commit is contained in:
Bill Currie 2002-02-13 00:57:00 +00:00
parent 42ba67eb4b
commit 814e2ddfe9

View file

@ -74,12 +74,10 @@ Q_snprintfz (char *dest, size_t size, const char *fmt, ...)
int len;
va_list argptr;
if (!size)
return -1;
va_start (argptr, fmt);
len = _vsnprintf (dest, size - 1, fmt, argptr);
va_end (argptr);
if (len < 0) // the string didn't fit into the buffer
if (len < 0 && size) // the string didn't fit into the buffer
dest[size - 1] = 0;
return len;
}
@ -89,11 +87,9 @@ Q_vsnprintfz (char *dest, size_t size, const char *fmt, va_list argptr)
{
int len;
if (!size)
return -1;
len = _vsnprintf (dest, size - 1, fmt, argptr);
if (len < 0) // the string didn't fit into the buffer
if (len < 0 && size) // the string didn't fit into the buffer
dest[size - 1] = 0;
return len;
}