From dac8a746a7f80b50834e750927335d8d1a00c1c1 Mon Sep 17 00:00:00 2001 From: thilo Date: Tue, 25 Mar 2008 21:36:09 +0000 Subject: - Replace vsprintf function in bg_lib.c with vsnprintf implementation started by Patrick Powell. - Remove all calls to vsprintf in the engine and gamecode and replace them with calls to vsnprintf. git-svn-id: svn://svn.icculus.org/quake3/trunk@1277 edf5b092-35ff-0310-97b2-ce42778d08ea --- code/qcommon/common.c | 2 +- code/qcommon/q_shared.c | 15 +++++++-------- code/qcommon/q_shared.h | 50 ++++++++++++++++++++++++++++++------------------- code/qcommon/qcommon.h | 10 ---------- 4 files changed, 39 insertions(+), 38 deletions(-) (limited to 'code/qcommon') diff --git a/code/qcommon/common.c b/code/qcommon/common.c index 41cbbc0..9482c04 100644 --- a/code/qcommon/common.c +++ b/code/qcommon/common.c @@ -269,7 +269,7 @@ void QDECL Com_Error( int code, const char *fmt, ... ) { com_errorEntered = qtrue; va_start (argptr,fmt); - vsprintf (com_errorMessage,fmt,argptr); + Q_vsnprintf (com_errorMessage, sizeof(com_errorMessage),fmt,argptr); va_end (argptr); if (code != ERR_DISCONNECT && code != ERR_NEED_CD) diff --git a/code/qcommon/q_shared.c b/code/qcommon/q_shared.c index 81e4e80..5ce6bbf 100644 --- a/code/qcommon/q_shared.c +++ b/code/qcommon/q_shared.c @@ -295,7 +295,7 @@ void COM_ParseError( char *format, ... ) static char string[4096]; va_start (argptr, format); - vsprintf (string, format, argptr); + Q_vsnprintf (string, sizeof(string), format, argptr); va_end (argptr); Com_Printf("ERROR: %s, line %d: %s\n", com_parsename, com_lines, string); @@ -307,7 +307,7 @@ void COM_ParseWarning( char *format, ... ) static char string[4096]; va_start (argptr, format); - vsprintf (string, format, argptr); + Q_vsnprintf (string, sizeof(string), format, argptr); va_end (argptr); Com_Printf("WARNING: %s, line %d: %s\n", com_parsename, com_lines, string); @@ -928,7 +928,7 @@ void QDECL Com_sprintf( char *dest, int size, const char *fmt, ...) { char bigbuffer[32000]; // big, but small enough to fit in PPC stack va_start (argptr,fmt); - len = vsprintf (bigbuffer,fmt,argptr); + len = Q_vsnprintf (bigbuffer, sizeof(bigbuffer), fmt,argptr); va_end (argptr); if ( len >= sizeof( bigbuffer ) ) { Com_Error( ERR_FATAL, "Com_sprintf: overflowed bigbuffer" ); @@ -951,20 +951,19 @@ va does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functions. -FIXME: make this buffer size safe someday ============ */ char * QDECL va( char *format, ... ) { va_list argptr; - static char string[2][32000]; // in case va is called by nested functions - static int index = 0; - char *buf; + static char string[2][32000]; // in case va is called by nested functions + static int index = 0; + char *buf; buf = string[index & 1]; index++; va_start (argptr, format); - vsprintf (buf, format,argptr); + Q_vsnprintf (buf, sizeof(*string), format, argptr); va_end (argptr); return buf; diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h index 9959f27..8f5dbe4 100644 --- a/code/qcommon/q_shared.h +++ b/code/qcommon/q_shared.h @@ -92,9 +92,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA **********************************************************************/ +#ifdef Q3_VM + #include "../game/bg_lib.h" -#ifndef Q3_VM +typedef int intptr_t; + +#else #include #include @@ -106,30 +110,38 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +// vsnprintf is ISO/IEC 9899:1999 +// abstracting this to make it portable +#ifdef _WIN32 + #define Q_vsnprintf _vsnprintf + #define Q_snprintf _snprintf +#else + #define Q_vsnprintf vsnprintf + #define Q_snprintf snprintf +#endif + +#ifdef _MSC_VER + #include + + typedef __int64 int64_t; + typedef __int32 int32_t; + typedef __int16 int16_t; + typedef __int8 int8_t; + typedef unsigned __int64 uint64_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int8 uint8_t; +#else + #include +#endif + #endif + #include "q_platform.h" //============================================================= -#ifdef Q3_VM - typedef int intptr_t; -#else - #ifndef _MSC_VER - #include - #else - #include - typedef __int64 int64_t; - typedef __int32 int32_t; - typedef __int16 int16_t; - typedef __int8 int8_t; - typedef unsigned __int64 uint64_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int8 uint8_t; - #endif -#endif - typedef unsigned char byte; typedef enum {qfalse, qtrue} qboolean; diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h index 817bbab..877b655 100644 --- a/code/qcommon/qcommon.h +++ b/code/qcommon/qcommon.h @@ -695,16 +695,6 @@ MISC ============================================================== */ -// vsnprintf is ISO/IEC 9899:1999 -// abstracting this to make it portable -#ifdef _WIN32 -#define Q_vsnprintf _vsnprintf -#define Q_snprintf _snprintf -#else -#define Q_vsnprintf vsnprintf -#define Q_snprintf snprintf -#endif - // centralizing the declarations for cl_cdkey // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470 extern char cl_cdkey[34]; -- cgit v1.2.3