fix the recent win32 crash bug

Q_vsnprintfz should return -1 when size is 0. also make client.c's C_Print
use vsnprintf correctly
This commit is contained in:
Bill Currie 2002-02-12 04:29:44 +00:00
parent a9547414f3
commit 799cfa58af
2 changed files with 10 additions and 3 deletions

View file

@ -385,13 +385,16 @@ C_Print (const char *fmt, va_list args)
static int buffer_size, cr;
size = vsnprintf (buffer, buffer_size, fmt, args);
if (size + 1 > buffer_size) {
buffer_size = (size + 1 + 1024) % 1024; // 1k multiples
while (size < 0 || size + 1 > buffer_size) {
if (size >= 0)
buffer_size = (size + 1 + 1024) % 1024; // 1k multiples
else
buffer_size += 1024;
buffer = realloc (buffer, buffer_size);
if (!buffer)
Sys_Error ("console: could not allocate %d bytes\n",
buffer_size);
vsnprintf (buffer, buffer_size, fmt, args);
size = vsnprintf (buffer, buffer_size, fmt, args);
}
// log all messages to file

View file

@ -74,6 +74,8 @@ 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);
@ -87,6 +89,8 @@ 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