- 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.
This commit is contained in:
Thilo Schulz 2008-03-25 21:36:09 +00:00
parent 5728fc2ec8
commit bb47026b5f
19 changed files with 813 additions and 309 deletions

2
README
View File

@ -144,7 +144,7 @@ New cvars
New commands
video [filename] - start video capture (use with demo command)
stopvideo - stop video capture
print - print out the contents of a cvar
print - print out the contents of a cvar
------------------------------------------------------------ Miscellaneous -----

View File

@ -60,7 +60,7 @@ void QDECL AAS_Error(char *fmt, ...)
va_list arglist;
va_start(arglist, fmt);
vsprintf(str, fmt, arglist);
Q_vsnprintf(str, sizeof(str), fmt, arglist);
va_end(arglist);
botimport.Print(PRT_FATAL, "%s", str);
} //end of the function AAS_Error

View File

@ -131,7 +131,7 @@ void QDECL SourceError(source_t *source, char *str, ...)
va_list ap;
va_start(ap, str);
vsprintf(text, str, ap);
Q_vsnprintf(text, sizeof(text), str, ap);
va_end(ap);
#ifdef BOTLIB
botimport.Print(PRT_ERROR, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text);
@ -155,7 +155,7 @@ void QDECL SourceWarning(source_t *source, char *str, ...)
va_list ap;
va_start(ap, str);
vsprintf(text, str, ap);
Q_vsnprintf(text, sizeof(text), str, ap);
va_end(ap);
#ifdef BOTLIB
botimport.Print(PRT_WARNING, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text);

View File

@ -236,7 +236,7 @@ void QDECL ScriptError(script_t *script, char *str, ...)
if (script->flags & SCFL_NOERRORS) return;
va_start(ap, str);
vsprintf(text, str, ap);
Q_vsnprintf(text, sizeof(text), str, ap);
va_end(ap);
#ifdef BOTLIB
botimport.Print(PRT_ERROR, "file %s, line %d: %s\n", script->filename, script->line, text);
@ -262,7 +262,7 @@ void QDECL ScriptWarning(script_t *script, char *str, ...)
if (script->flags & SCFL_NOWARNINGS) return;
va_start(ap, str);
vsprintf(text, str, ap);
Q_vsnprintf(text, sizeof(text), str, ap);
va_end(ap);
#ifdef BOTLIB
botimport.Print(PRT_WARNING, "file %s, line %d: %s\n", script->filename, script->line, text);

View File

@ -419,7 +419,7 @@ void QDECL CG_Printf( const char *msg, ... ) {
char text[1024];
va_start (argptr, msg);
vsprintf (text, msg, argptr);
Q_vsnprintf (text, sizeof(text), msg, argptr);
va_end (argptr);
trap_Print( text );
@ -430,7 +430,7 @@ void QDECL CG_Error( const char *msg, ... ) {
char text[1024];
va_start (argptr, msg);
vsprintf (text, msg, argptr);
Q_vsnprintf (text, sizeof(text), msg, argptr);
va_end (argptr);
trap_Error( text );
@ -441,7 +441,7 @@ void QDECL Com_Error( int level, const char *error, ... ) {
char text[1024];
va_start (argptr, error);
vsprintf (text, error, argptr);
Q_vsnprintf (text, sizeof(text), error, argptr);
va_end (argptr);
CG_Error( "%s", text);
@ -452,7 +452,7 @@ void QDECL Com_Printf( const char *msg, ... ) {
char text[1024];
va_start (argptr, msg);
vsprintf (text, msg, argptr);
Q_vsnprintf (text, sizeof(text), msg, argptr);
va_end (argptr);
CG_Printf ("%s", text);

View File

@ -99,7 +99,7 @@ void QDECL BotAI_Print(int type, char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsprintf(str, fmt, ap);
Q_vsnprintf(str, sizeof(str), fmt, ap);
va_end(ap);
switch(type) {

File diff suppressed because it is too large Load Diff

View File

@ -98,7 +98,9 @@ double _atof( const char **stringPtr );
int atoi( const char *string );
int _atoi( const char **stringPtr );
int vsprintf( char *buffer, const char *fmt, va_list argptr );
int Q_vsnprintf( char *buffer, size_t length, const char *fmt, va_list argptr );
int Q_snprintf( char *buffer, size_t length, const char *fmt, ... ) __attribute__ ((format (printf, 3, 4)));
int sscanf( const char *buffer, const char *fmt, ... ) __attribute__ ((format (scanf, 2, 3)));
// Memory functions

View File

@ -241,7 +241,7 @@ void QDECL G_Printf( const char *fmt, ... ) {
char text[1024];
va_start (argptr, fmt);
vsprintf (text, fmt, argptr);
Q_vsnprintf (text, sizeof(text), fmt, argptr);
va_end (argptr);
trap_Printf( text );
@ -252,7 +252,7 @@ void QDECL G_Error( const char *fmt, ... ) {
char text[1024];
va_start (argptr, fmt);
vsprintf (text, fmt, argptr);
Q_vsnprintf (text, sizeof(text), fmt, argptr);
va_end (argptr);
trap_Error( text );
@ -539,7 +539,7 @@ void QDECL Com_Error ( int level, const char *error, ... ) {
char text[1024];
va_start (argptr, error);
vsprintf (text, error, argptr);
Q_vsnprintf (text, sizeof(text), error, argptr);
va_end (argptr);
G_Error( "%s", text);
@ -550,7 +550,7 @@ void QDECL Com_Printf( const char *msg, ... ) {
char text[1024];
va_start (argptr, msg);
vsprintf (text, msg, argptr);
Q_vsnprintf (text, sizeof(text), msg, argptr);
va_end (argptr);
G_Printf ("%s", text);
@ -1092,7 +1092,7 @@ void QDECL G_LogPrintf( const char *fmt, ... ) {
Com_sprintf( string, sizeof(string), "%3i:%i%i ", min, tens, sec );
va_start( argptr, fmt );
vsprintf( string +7 , fmt,argptr );
Q_vsnprintf(string + 7, sizeof(string - 7), fmt, argptr);
va_end( argptr );
if ( g_dedicated.integer ) {

View File

@ -108,7 +108,7 @@ void QDECL PrintMsg( gentity_t *ent, const char *fmt, ... ) {
char *p;
va_start (argptr,fmt);
if (vsprintf (msg, fmt, argptr) > sizeof(msg)) {
if (Q_vsnprintf (msg, sizeof(msg), fmt, argptr) > sizeof(msg)) {
G_Error ( "PrintMsg overrun" );
}
va_end (argptr);

View File

@ -35,7 +35,7 @@ void QDECL Com_Error( int level, const char *error, ... ) {
char text[1024];
va_start (argptr, error);
vsprintf (text, error, argptr);
Q_vsnprintf (text, sizeof(text), error, argptr);
va_end (argptr);
trap_Error( va("%s", text) );
@ -46,7 +46,7 @@ void QDECL Com_Printf( const char *msg, ... ) {
char text[1024];
va_start (argptr, msg);
vsprintf (text, msg, argptr);
Q_vsnprintf (text, sizeof(text), msg, argptr);
va_end (argptr);
trap_Print( va("%s", text) );

View File

@ -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)

View File

@ -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;

View File

@ -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 <assert.h>
#include <math.h>
@ -106,30 +110,38 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <ctype.h>
#include <limits.h>
// 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 <io.h>
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 <stdint.h>
#endif
#endif
#include "q_platform.h"
//=============================================================
#ifdef Q3_VM
typedef int intptr_t;
#else
#ifndef _MSC_VER
#include <stdint.h>
#else
#include <io.h>
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;

View File

@ -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];

View File

@ -139,7 +139,7 @@ void QDECL BotImport_Print(int type, char *fmt, ...)
va_list ap;
va_start(ap, fmt);
vsprintf(str, fmt, ap);
Q_vsnprintf(str, sizeof(str), fmt, ap);
va_end(ap);
switch(type) {

View File

@ -1523,7 +1523,7 @@ static void SV_RankError( const char* fmt, ... )
char text[1024];
va_start( arg_ptr, fmt );
vsprintf( text, fmt, arg_ptr );
Q_vsnprintf(text, sizeof(text), fmt, arg_ptr );
va_end( arg_ptr );
Com_DPrintf( "****************************************\n" );

View File

@ -34,7 +34,7 @@ void QDECL Com_Error( int level, const char *error, ... ) {
char text[1024];
va_start (argptr, error);
vsprintf (text, error, argptr);
Q_vsnprintf (text, sizeof(text), error, argptr);
va_end (argptr);
trap_Error( va("%s", text) );
@ -45,7 +45,7 @@ void QDECL Com_Printf( const char *msg, ... ) {
char text[1024];
va_start (argptr, msg);
vsprintf (text, msg, argptr);
Q_vsnprintf (text, sizeof(text), msg, argptr);
va_end (argptr);
trap_Print( va("%s", text) );

View File

@ -258,7 +258,7 @@ void PC_SourceWarning(int handle, char *format, ...) {
static char string[4096];
va_start (argptr, format);
vsprintf (string, format, argptr);
Q_vsnprintf (string, sizeof(string), format, argptr);
va_end (argptr);
filename[0] = '\0';
@ -280,7 +280,7 @@ void PC_SourceError(int handle, char *format, ...) {
static char string[4096];
va_start (argptr, format);
vsprintf (string, format, argptr);
Q_vsnprintf (string, sizeof(string), format, argptr);
va_end (argptr);
filename[0] = '\0';