diff options
author | Tim Angus <tim@ngus.net> | 2007-03-21 23:55:51 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2007-03-21 23:55:51 +0000 |
commit | d899c25c571ed061bba9725cf7b35d492cc6e518 (patch) | |
tree | 25268c9b3e381d00c2885c1fec7a54f46f56d93b /src/qcommon | |
parent | cb5b4648d45b3f078a6ae3da45707764ca46e241 (diff) |
* ioq3-r1052 merge
Diffstat (limited to 'src/qcommon')
-rw-r--r-- | src/qcommon/common.c | 21 | ||||
-rw-r--r-- | src/qcommon/cvar.c | 5 | ||||
-rw-r--r-- | src/qcommon/files.c | 31 | ||||
-rw-r--r-- | src/qcommon/md5.c | 23 | ||||
-rw-r--r-- | src/qcommon/net_chan.c | 5 | ||||
-rw-r--r-- | src/qcommon/q_platform.h | 2 | ||||
-rw-r--r-- | src/qcommon/q_shared.c | 46 | ||||
-rw-r--r-- | src/qcommon/q_shared.h | 39 | ||||
-rw-r--r-- | src/qcommon/qcommon.h | 14 | ||||
-rw-r--r-- | src/qcommon/vm.c | 2 | ||||
-rw-r--r-- | src/qcommon/vm_interpreted.c | 2 | ||||
-rw-r--r-- | src/qcommon/vm_x86_64.c | 6 |
12 files changed, 106 insertions, 90 deletions
diff --git a/src/qcommon/common.c b/src/qcommon/common.c index aa0bb668..cdfe3386 100644 --- a/src/qcommon/common.c +++ b/src/qcommon/common.c @@ -3080,3 +3080,24 @@ void Field_AutoComplete( field_t *field ) Field_CompleteCommand( completionField->buffer, qtrue, qtrue ); } + +/* +================== +Com_RandomBytes + +fills string array with len radom bytes, peferably from the OS randomizer +================== +*/ +void Com_RandomBytes( byte *string, int len ) +{ + int i; + + if( Sys_RandomBytes( string, len ) ) + return; + + Com_Printf( "Com_RandomBytes: using weak randomization\n" ); + srand( time( 0 ) ); + for( i = 0; i < len; i++ ) + string[i] = (unsigned char)( rand() % 255 ); +} + diff --git a/src/qcommon/cvar.c b/src/qcommon/cvar.c index 4340dcc4..91d3dfbe 100644 --- a/src/qcommon/cvar.c +++ b/src/qcommon/cvar.c @@ -911,10 +911,9 @@ void Cvar_Update( vmCvar_t *vmCvar ) { vmCvar->modificationCount = cv->modificationCount; // bk001129 - mismatches. if ( strlen(cv->string)+1 > MAX_CVAR_VALUE_STRING ) - Com_Error( ERR_DROP, "Cvar_Update: src %s length %d exceeds MAX_CVAR_VALUE_STRING", + Com_Error( ERR_DROP, "Cvar_Update: src %s length %zd exceeds MAX_CVAR_VALUE_STRING", cv->string, - strlen(cv->string), - sizeof(vmCvar->string) ); + strlen(cv->string)); // bk001212 - Q_strncpyz guarantees zero padding and dest[MAX_CVAR_VALUE_STRING-1]==0 // bk001129 - paranoia. Never trust the destination string. // bk001129 - beware, sizeof(char*) is always 4 (for cv->string). diff --git a/src/qcommon/files.c b/src/qcommon/files.c index ac73a0a8..cd369908 100644 --- a/src/qcommon/files.c +++ b/src/qcommon/files.c @@ -197,12 +197,20 @@ or configs will never get loaded from disk! */ -#define DEMOGAME "demota" - // every time a new demo pk3 file is built, this checksum must be updated. // the easiest way to get it is to just run the game and see what it spits out #define DEMO_PAK0_CHECKSUM 2985612116u -#define PAK0_CHECKSUM 1566731103u +static const unsigned pak_checksums[] = { + 1566731103u, + 298122907u, + 412165236u, + 2991495316u, + 1197932710u, + 4087071573u, + 3709064859u, + 908855077u, + 977125798u +}; // if this is defined, the executable positively won't work with any paks other // than the demo pak, even if productid is present. This is only used for our @@ -2477,7 +2485,6 @@ Sets fs_gamedir, adds the directory to the head of the path, then loads the zip headers ================ */ -#define MAX_PAKFILES 1024 static void FS_AddGameDirectory( const char *path, const char *dir ) { searchpath_t *sp; int i; @@ -2486,7 +2493,6 @@ static void FS_AddGameDirectory( const char *path, const char *dir ) { char *pakfile; int numfiles; char **pakfiles; - char *sorted[MAX_PAKFILES]; // this fixes the case where fs_basepath is the same as fs_cdpath // which happens on full installs @@ -2515,20 +2521,11 @@ static void FS_AddGameDirectory( const char *path, const char *dir ) { pakfiles = Sys_ListFiles( pakfile, ".pk3", NULL, &numfiles, qfalse ); - // sort them so that later alphabetic matches override - // earlier ones. This makes pak1.pk3 override pak0.pk3 - if ( numfiles > MAX_PAKFILES ) { - numfiles = MAX_PAKFILES; - } - for ( i = 0 ; i < numfiles ; i++ ) { - sorted[i] = pakfiles[i]; - } - - qsort( sorted, numfiles, sizeof(char*), paksort ); + qsort( pakfiles, numfiles, sizeof(char*), paksort ); for ( i = 0 ; i < numfiles ; i++ ) { - pakfile = FS_BuildOSPath( path, dir, sorted[i] ); - if ( ( pak = FS_LoadZipFile( pakfile, sorted[i] ) ) == 0 ) + pakfile = FS_BuildOSPath( path, dir, pakfiles[i] ); + if ( ( pak = FS_LoadZipFile( pakfile, pakfiles[i] ) ) == 0 ) continue; // store the game name for downloading strcpy(pak->pakGamename, dir); diff --git a/src/qcommon/md5.c b/src/qcommon/md5.c index ffe77527..5cf12bb3 100644 --- a/src/qcommon/md5.c +++ b/src/qcommon/md5.c @@ -257,20 +257,27 @@ static void MD5Final(struct MD5Context *ctx, unsigned char *digest) } -char *Com_MD5File(const char *fn, int length) +char *Com_MD5File( const char *fn, int length, const char *prefix, int prefix_len ) { - static char final[33] = {"unknown"}; + static char final[33] = {""}; unsigned char digest[16] = {""}; fileHandle_t f; MD5_CTX md5; - char buffer[2048]; + byte buffer[2048]; int i; int filelen = 0; int r = 0; int total = 0; - filelen = FS_FOpenFileRead(fn, &f, qtrue); - if(filelen < 1) { + Q_strncpyz( final, "", sizeof( final ) ); + + filelen = FS_SV_FOpenFileRead( fn, &f ); + + if( !f ) { + return final; + } + if( filelen < 1 ) { + FS_FCloseFile( f ); return final; } if(filelen < length || !length) { @@ -278,6 +285,10 @@ char *Com_MD5File(const char *fn, int length) } MD5Init(&md5); + + if( prefix_len && *prefix ) + MD5Update(&md5 , (unsigned char *)prefix, prefix_len); + for(;;) { r = FS_Read2(buffer, sizeof(buffer), f); if(r < 1) @@ -285,7 +296,7 @@ char *Com_MD5File(const char *fn, int length) if(r + total > length) r = length - total; total += r; - MD5Update(&md5 , (unsigned char *)buffer, r); + MD5Update(&md5 , buffer, r); if(r < sizeof(buffer) || total >= length) break; } diff --git a/src/qcommon/net_chan.c b/src/qcommon/net_chan.c index 9dd41589..869d87a3 100644 --- a/src/qcommon/net_chan.c +++ b/src/qcommon/net_chan.c @@ -398,8 +398,7 @@ qboolean Netchan_Process( netchan_t *chan, msg_t *msg ) { if ( fragmentStart != chan->fragmentLength ) { if ( showdrop->integer || showpackets->integer ) { Com_Printf( "%s:Dropped a message fragment\n" - , NET_AdrToString( chan->remoteAddress ) - , sequence); + , NET_AdrToString( chan->remoteAddress )); } // we can still keep the part that we have so far, // so we don't need to clear chan->fragmentLength @@ -716,7 +715,7 @@ void QDECL NET_OutOfBandPrint( netsrc_t sock, netadr_t adr, const char *format, string[3] = -1; va_start( argptr, format ); - vsprintf( string+4, format, argptr ); + Q_vsnprintf( string+4, sizeof(string)-4, format, argptr ); va_end( argptr ); // send the datagram diff --git a/src/qcommon/q_platform.h b/src/qcommon/q_platform.h index 2e0a6aca..ad9a9382 100644 --- a/src/qcommon/q_platform.h +++ b/src/qcommon/q_platform.h @@ -223,7 +223,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifdef __sun -#include <sys/isa_defs.h> +#include <stdint.h> #include <sys/byteorder.h> #define OS_STRING "solaris" diff --git a/src/qcommon/q_shared.c b/src/qcommon/q_shared.c index 93c1dc20..aa8d55d5 100644 --- a/src/qcommon/q_shared.c +++ b/src/qcommon/q_shared.c @@ -1188,29 +1188,21 @@ Changes or adds a key/value pair */ void Info_SetValueForKey( char *s, const char *key, const char *value ) { char newi[MAX_INFO_STRING]; + const char* blacklist = "\\;\""; if ( strlen( s ) >= MAX_INFO_STRING ) { Com_Error( ERR_DROP, "Info_SetValueForKey: oversize infostring" ); } - if (strchr (key, '\\') || strchr (value, '\\')) + for(; *blacklist; ++blacklist) { - Com_Printf ("Can't use keys or values with a \\\n"); - return; - } - - if (strchr (key, ';') || strchr (value, ';')) - { - Com_Printf ("Can't use keys or values with a semicolon\n"); - return; - } - - if (strchr (key, '\"') || strchr (value, '\"')) - { - Com_Printf ("Can't use keys or values with a \"\n"); - return; + if (strchr (key, *blacklist) || strchr (value, *blacklist)) + { + Com_Printf (S_COLOR_YELLOW "Can't use keys or values with a '%c': %s = %s\n", *blacklist, key, value); + return; + } } - + Info_RemoveKey (s, key); if (!value || !strlen(value)) return; @@ -1236,27 +1228,19 @@ Changes or adds a key/value pair */ void Info_SetValueForKey_Big( char *s, const char *key, const char *value ) { char newi[BIG_INFO_STRING]; + const char* blacklist = "\\;\""; if ( strlen( s ) >= BIG_INFO_STRING ) { Com_Error( ERR_DROP, "Info_SetValueForKey: oversize infostring" ); } - if (strchr (key, '\\') || strchr (value, '\\')) + for(; *blacklist; ++blacklist) { - Com_Printf ("Can't use keys or values with a \\\n"); - return; - } - - if (strchr (key, ';') || strchr (value, ';')) - { - Com_Printf ("Can't use keys or values with a semicolon\n"); - return; - } - - if (strchr (key, '\"') || strchr (value, '\"')) - { - Com_Printf ("Can't use keys or values with a \"\n"); - return; + if (strchr (key, *blacklist) || strchr (value, *blacklist)) + { + Com_Printf (S_COLOR_YELLOW "Can't use keys or values with a '%c': %s = %s\n", *blacklist, key, value); + return; + } } Info_RemoveKey_Big (s, key); diff --git a/src/qcommon/q_shared.h b/src/qcommon/q_shared.h index 3f0ae9a2..50a0b10c 100644 --- a/src/qcommon/q_shared.h +++ b/src/qcommon/q_shared.h @@ -113,18 +113,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifdef Q3_VM typedef int intptr_t; #else -# ifndef _MSC_VER -# include <stdint.h> -# else - 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 + #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; @@ -656,8 +657,8 @@ int COM_GetCurrentParseLine( void ); char *COM_Parse( char **data_p ); char *COM_ParseExt( char **data_p, qboolean allowLineBreak ); int COM_Compress( char *data_p ); -void COM_ParseError( char *format, ... ); -void COM_ParseWarning( char *format, ... ); +void COM_ParseError( char *format, ... ) __attribute__ ((format (printf, 1, 2))); +void COM_ParseWarning( char *format, ... ) __attribute__ ((format (printf, 1, 2))); //int COM_ParseInfos( char *buf, int max, char infos[][MAX_INFO_STRING] ); #define MAX_TOKENLENGTH 1024 @@ -691,11 +692,13 @@ void Parse1DMatrix (char **buf_p, int x, float *m); void Parse2DMatrix (char **buf_p, int y, int x, float *m); void Parse3DMatrix (char **buf_p, int z, int y, int x, float *m); -void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...); +void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); char *Com_SkipTokens( char *s, int numTokens, char *sep ); char *Com_SkipCharset( char *s, char *sep ); +void Com_RandomBytes( byte *string, int len ); + // mode parm for FS_FOpenFile typedef enum { FS_READ, @@ -763,7 +766,7 @@ float LittleFloat (const float *l); void Swap_Init (void); */ -char * QDECL va(char *format, ...); +char * QDECL va(char *format, ...) __attribute__ ((format (printf, 1, 2))); #define TRUNCATE_LENGTH 64 void Com_TruncateLongString( char *buffer, const char *s ); @@ -782,8 +785,8 @@ qboolean Info_Validate( const char *s ); void Info_NextPair( const char **s, char *key, char *value ); // this is only here so the functions in q_shared.c and bg_*.c can link -void QDECL Com_Error( int level, const char *error, ... ); -void QDECL Com_Printf( const char *msg, ... ); +void QDECL Com_Error( int level, const char *error, ... ) __attribute__ ((format (printf, 2, 3))); +void QDECL Com_Printf( const char *msg, ... ) __attribute__ ((format (printf, 1, 2))); /* diff --git a/src/qcommon/qcommon.h b/src/qcommon/qcommon.h index 2279fb12..630d4da9 100644 --- a/src/qcommon/qcommon.h +++ b/src/qcommon/qcommon.h @@ -159,7 +159,7 @@ void NET_Restart( void ); void NET_Config( qboolean enableNetworking ); void NET_FlushPacketQueue(void); void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to); -void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...); +void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...) __attribute__ ((format (printf, 3, 4))); void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len ); qboolean NET_CompareAdr (netadr_t a, netadr_t b); @@ -715,14 +715,14 @@ void Info_Print( const char *s ); void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *)); void Com_EndRedirect( void ); -void QDECL Com_Printf( const char *fmt, ... ); -void QDECL Com_DPrintf( const char *fmt, ... ); -void QDECL Com_Error( int code, const char *fmt, ... ); +void QDECL Com_Printf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2))); +void QDECL Com_DPrintf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2))); +void QDECL Com_Error( int code, const char *fmt, ... ) __attribute__ ((format (printf, 2, 3))); void Com_Quit_f( void ); int Com_EventLoop( void ); int Com_Milliseconds( void ); // will be journaled properly unsigned Com_BlockChecksum( const void *buffer, int length ); -char *Com_MD5File(const char *filename, int length); +char *Com_MD5File(const char *filename, int length, const char *prefix, int prefix_len); int Com_HashKey(char *string, int maxlen); int Com_Filter(char *filter, char *name, int casesensitive); int Com_FilterPath(char *filter, char *name, int casesensitive); @@ -978,7 +978,7 @@ void *Sys_GetBotLibAPI( void *parms ); char *Sys_GetCurrentUser( void ); -void QDECL Sys_Error( const char *error, ...); +void QDECL Sys_Error( const char *error, ...) __attribute__ ((format (printf, 1, 2))); void Sys_Quit (void); char *Sys_GetClipboardData( void ); // note that this isn't journaled... @@ -990,6 +990,8 @@ int Sys_Milliseconds (void); void Sys_SnapVector( float *v ); +qboolean Sys_RandomBytes( byte *string, int len ); + // the system console is shown when a dedicated server is running void Sys_DisplaySystemConsole( qboolean show ); diff --git a/src/qcommon/vm.c b/src/qcommon/vm.c index 8fb588db..0017b417 100644 --- a/src/qcommon/vm.c +++ b/src/qcommon/vm.c @@ -727,7 +727,7 @@ intptr_t QDECL VM_Call( vm_t *vm, int callnum, ... ) { lastVM = vm; if ( vm_debugLevel ) { - Com_Printf( "VM_Call( %ld )\n", callnum ); + Com_Printf( "VM_Call( %d )\n", callnum ); } // if we have a dll loaded, call it directly diff --git a/src/qcommon/vm_interpreted.c b/src/qcommon/vm_interpreted.c index 3c52f421..00aa4710 100644 --- a/src/qcommon/vm_interpreted.c +++ b/src/qcommon/vm_interpreted.c @@ -908,7 +908,7 @@ done: vm->currentlyInterpreting = qfalse; if ( opStack != &stack[1] ) { - Com_Error( ERR_DROP, "Interpreter error: opStack = %i", opStack - stack ); + Com_Error( ERR_DROP, "Interpreter error: opStack = %ld", (long int) (opStack - stack) ); } vm->programStack = stackOnEntry; diff --git a/src/qcommon/vm_x86_64.c b/src/qcommon/vm_x86_64.c index 822c3e1d..9fde6e75 100644 --- a/src/qcommon/vm_x86_64.c +++ b/src/qcommon/vm_x86_64.c @@ -423,7 +423,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { unlink(fn_s); unlink(fn_o); - Com_Printf(S_COLOR_RED "can't create temporary files for vm\n", fn_s); + Com_Printf(S_COLOR_RED "can't create temporary file %s for vm\n", fn_s); vm->compiled = qfalse; return; } @@ -896,7 +896,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { fflush(qdasmout); #endif - Com_Printf( "VM file %s compiled to %i bytes of code (0x%lx - 0x%lx)\n", vm->name, vm->codeLength, vm->codeBase, vm->codeBase+vm->codeLength ); + Com_Printf( "VM file %s compiled to %i bytes of code (%p - %p)\n", vm->name, vm->codeLength, vm->codeBase, vm->codeBase+vm->codeLength ); out: close(fd_o); @@ -991,7 +991,7 @@ int VM_CallCompiled( vm_t *vm, int *args ) { ); if ( opStack != &stack[1] ) { - Com_Error( ERR_DROP, "opStack corrupted in compiled code (offset %d)\n", (void*)&stack[1] - opStack); + Com_Error( ERR_DROP, "opStack corrupted in compiled code (offset %ld)\n", (long int) ((void *) &stack[1] - opStack)); } if ( programStack != stackOnEntry - 48 ) { Com_Error( ERR_DROP, "programStack corrupted in compiled code\n" ); |