summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2008-04-02 23:03:09 +0000
committerAndrey Nazarov <skuller@skuller.net>2008-04-02 23:03:09 +0000
commit7ec50f12252b4dfb97f3249ccf05a771b98785c1 (patch)
tree279e4e8bd7b940368331a43869c165de9637ae99
parent80e48417564f1ce50a39a7c552ad95e651362c1f (diff)
Use size_t instead of int where possible.
Added initial support for Win64 port.
-rwxr-xr-xconfigure2
-rw-r--r--source/cl_console.c4
-rw-r--r--source/cl_demo.c33
-rw-r--r--source/cl_draw.c10
-rw-r--r--source/cl_fx.c5
-rw-r--r--source/cl_input.c26
-rw-r--r--source/cl_locs.c10
-rw-r--r--source/cl_main.c22
-rw-r--r--source/cl_parse.c24
-rw-r--r--source/cmd.c23
-rw-r--r--source/cmodel.c8
-rw-r--r--source/com_local.h111
-rw-r--r--source/com_public.h24
-rw-r--r--source/common.c91
-rw-r--r--source/crc.c34
-rw-r--r--source/cvar.c6
-rw-r--r--source/files.c171
-rw-r--r--source/gl_draw.c2
-rw-r--r--source/gl_images.c9
-rw-r--r--source/gl_local.h2
-rw-r--r--source/gl_main.c2
-rw-r--r--source/gl_models.c19
-rw-r--r--source/mdfour.c8
-rw-r--r--source/mdfour.h2
-rw-r--r--source/mvd_client.c23
-rw-r--r--source/mvd_game.c9
-rw-r--r--source/mvd_local.h36
-rw-r--r--source/mvd_parse.c70
-rw-r--r--source/net_chan.c61
-rw-r--r--source/net_common.c32
-rw-r--r--source/prompt.c31
-rw-r--r--source/q_field.c28
-rw-r--r--source/q_field.h10
-rw-r--r--source/q_msg.c38
-rw-r--r--source/q_msg.h22
-rw-r--r--source/q_shared.c52
-rw-r--r--source/q_shared.h13
-rw-r--r--source/r_bsp.c2
-rw-r--r--source/r_images.c22
-rw-r--r--source/ref_public.h2
-rw-r--r--source/snd_mem.c2
-rw-r--r--source/sv_ac.c32
-rw-r--r--source/sv_ccmds.c8
-rw-r--r--source/sv_game.c26
-rw-r--r--source/sv_http.c39
-rw-r--r--source/sv_local.h20
-rw-r--r--source/sv_main.c49
-rw-r--r--source/sv_mvd.c13
-rw-r--r--source/sv_send.c86
-rw-r--r--source/sv_user.c18
-rw-r--r--source/sw_draw.c2
-rw-r--r--source/sw_image.c8
-rw-r--r--source/sw_main.c2
-rw-r--r--source/sys_unix.c4
-rw-r--r--source/sys_win.c119
-rw-r--r--source/ui_addressbook.c2
-rw-r--r--source/ui_atoms.c5
-rw-r--r--source/ui_demos.c11
-rw-r--r--source/ui_network.c6
-rw-r--r--source/ui_playerconfig.c2
-rw-r--r--source/ui_playermodels.c2
61 files changed, 771 insertions, 784 deletions
diff --git a/configure b/configure
index 41e6aa9..dd9e820 100755
--- a/configure
+++ b/configure
@@ -521,7 +521,7 @@ else
echo "#define DEFAULT_REFRESH_DRIVER \"soft\"" >> $config_h
fi
-echo "#define PRIz \"z\"" >> $config_h
+echo "#define PRIz \"zu\"" >> $config_h
for t in $targets ; do
mkdir -p .$t ;
diff --git a/source/cl_console.c b/source/cl_console.c
index c666365..dcf78e2 100644
--- a/source/cl_console.c
+++ b/source/cl_console.c
@@ -406,8 +406,8 @@ void Con_Init( void ) {
con_scroll = Cvar_Get( "con_scroll", "0", CVAR_ARCHIVE );
con_history = Cvar_Get( "con_history", "0", 0 );
- IF_Init( &con.prompt.inputLine, 1, MAX_FIELD_TEXT );
- IF_Init( &con.chatPrompt.inputLine, 1, MAX_FIELD_TEXT );
+ IF_Init( &con.prompt.inputLine, 1, MAX_FIELD_TEXT, NULL );
+ IF_Init( &con.chatPrompt.inputLine, 1, MAX_FIELD_TEXT, NULL );
con.prompt.printf = Con_Printf;
diff --git a/source/cl_demo.c b/source/cl_demo.c
index 1afb76e..c56f0ec 100644
--- a/source/cl_demo.c
+++ b/source/cl_demo.c
@@ -34,7 +34,7 @@ Dumps the current demo message, prefixed by the length.
====================
*/
void CL_WriteDemoMessage( sizebuf_t *buf ) {
- int length;
+ uint32_t length;
if( buf->overflowed ) {
SZ_Clear( buf );
@@ -170,7 +170,7 @@ void CL_EmitDemoFrame( void ) {
CL_EmitPacketEntities( oldframe, &cl.frame );
if( cls.demobuff.cursize + msg_write.cursize > cls.demobuff.maxsize ) {
- Com_WPrintf( "Oversize demo frame: %d bytes\n",
+ Com_WPrintf( "Oversize demo frame: %"PRIz" bytes\n",
cls.demobuff.cursize + msg_write.cursize );
} else {
SZ_Write( &cls.demobuff, msg_write.data, msg_write.cursize );
@@ -213,7 +213,7 @@ stop recording a demo
====================
*/
void CL_Stop_f( void ) {
- int length;
+ uint32_t length;
if( !cls.demorecording ) {
Com_Printf( "Not recording a demo.\n" );
@@ -229,7 +229,7 @@ void CL_Stop_f( void ) {
}
// finish up
- length = -1;
+ length = ( uint32_t )-1;
FS_Write( &length, 4, cls.demorecording );
length = FS_RawTell( cls.demorecording );
@@ -239,7 +239,7 @@ void CL_Stop_f( void ) {
cls.demorecording = 0;
cls.demopaused = qfalse;
- Com_Printf( "Stopped demo (%d bytes written).\n", length );
+ Com_Printf( "Stopped demo (%u bytes written).\n", length );
}
/*
@@ -253,7 +253,8 @@ Begins recording a demo from the current position
*/
void CL_Record_f( void ) {
char name[MAX_OSPATH];
- int i, length;
+ int i;
+ size_t length;
entity_state_t *ent;
char *string;
fileHandle_t demofile;
@@ -378,7 +379,7 @@ void CL_Record_f( void ) {
static void CL_Suspend_f( void ) {
int i, j, index;
- int length, total = 0;
+ size_t length, total = 0;
if( !cls.demorecording ) {
Com_Printf( "Not recording a demo.\n" );
@@ -418,7 +419,7 @@ static void CL_Suspend_f( void ) {
// write it to the demo file
CL_WriteDemoMessage( &msg_write );
- Com_Printf( "Resumed demo (%d bytes flushed).\n", total );
+ Com_Printf( "Resumed demo (%"PRIz" bytes flushed).\n", total );
cl.demodelta += cl.demoframe - cl.frame.number; // do not create holes
cls.demopaused = qfalse;
@@ -554,8 +555,8 @@ static void CL_PlayDemo_f( void ) {
char name[MAX_OSPATH];
fileHandle_t demofile;
char *arg;
- int length, type;
- int argc = Cmd_Argc();
+ size_t length;
+ int type, argc = Cmd_Argc();
if( argc < 2 ) {
Com_Printf( "Usage: %s <filename> [...]\n", Cmd_Argv( 0 ) );
@@ -631,13 +632,13 @@ static void CL_PlayDemo_f( void ) {
CL_ParseNextDemoMessage();
}
- length = FS_GetFileLengthNoCache( demofile );
- if( length > 0 ) {
- cls.demofileFrameOffset = FS_Tell( demofile );
- cls.demofileSize = length - cls.demofileFrameOffset;
- } else {
+ length = FS_GetFileLength( demofile );
+ if( length == INVALID_LENGTH ) {
cls.demofileFrameOffset = 0;
cls.demofileSize = 0;
+ } else {
+ cls.demofileFrameOffset = FS_Tell( demofile );
+ cls.demofileSize = length - cls.demofileFrameOffset;
}
if( com_timedemo->integer ) {
@@ -653,7 +654,7 @@ static void CL_Demo_c( genctx_t *ctx, int argnum ) {
}
static void CL_ParseInfoString( demoInfo_t *info, int clientNum, int index, const char *string ) {
- int len;
+ size_t len;
char *p;
if( index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS ) {
diff --git a/source/cl_draw.c b/source/cl_draw.c
index e674dda..eddb357 100644
--- a/source/cl_draw.c
+++ b/source/cl_draw.c
@@ -67,7 +67,7 @@ STAT PROGRAMS TO TEXT
#define TH_WIDTH 80
#define TH_HEIGHT 40
-static void TH_DrawString( char *dst, int x, int y, char *src, int len ) {
+static void TH_DrawString( char *dst, int x, int y, char *src, size_t len ) {
int c;
if( x + len > TH_WIDTH ) {
@@ -94,7 +94,7 @@ static void TH_DrawString( char *dst, int x, int y, char *src, int len ) {
}
}
-static void TH_DrawCenterString( char *dst, int x, int y, char *src, int len ) {
+static void TH_DrawCenterString( char *dst, int x, int y, char *src, size_t len ) {
x -= len / 2;
if( x < 0 ) {
src -= x;
@@ -128,8 +128,8 @@ static void TH_DrawLayoutString( char *dst, const char *s ) {
int x, y;
int value;
char *token;
- int width, len;
- int index;
+ size_t len;
+ int width, index;
clientinfo_t *ci;
if( !s[0] )
@@ -341,7 +341,7 @@ static void SCR_ScoreShot_f( void ) {
} else {
for( i = 0; i < 1000; i++ ) {
Com_sprintf( path, sizeof( path ), SCORESHOTS_DIRECTORY "/quake%03d.txt", i );
- if( FS_LoadFileEx( path, NULL, FS_PATH_GAME ) == -1 ) {
+ if( FS_LoadFileEx( path, NULL, FS_PATH_GAME ) == INVALID_LENGTH ) {
break; // file doesn't exist
}
}
diff --git a/source/cl_fx.c b/source/cl_fx.c
index 2723964..f959ff9 100644
--- a/source/cl_fx.c
+++ b/source/cl_fx.c
@@ -82,14 +82,15 @@ void CL_RunLightStyles( void ) {
void CL_SetLightstyle( int index ) {
char *s;
- int length, i;
+ size_t length;
+ int i;
clightstyle_t *dest;
s = cl.configstrings[index + CS_LIGHTS];
length = strlen( s );
if( length >= MAX_QPATH )
- Com_Error( ERR_DROP, "CL_SetLightstyle: length=%i", length );
+ Com_Error( ERR_DROP, "CL_SetLightstyle: bad length" );
dest = &cl_lightstyles[index];
dest->length = length;
diff --git a/source/cl_input.c b/source/cl_input.c
index 6dc1c70..bfbd8e8 100644
--- a/source/cl_input.c
+++ b/source/cl_input.c
@@ -803,8 +803,7 @@ CL_SendDefaultCmd
=================
*/
static void CL_SendDefaultCmd( void ) {
- int i;
- int checksumIndex;
+ size_t cursize, checksumIndex;
usercmd_t *cmd, *oldcmd;
client_history_t *history;
@@ -871,13 +870,9 @@ static void CL_SendDefaultCmd( void ) {
//
// deliver the message
//
- i = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data );
- if( i == -1 ) {
- Com_Error( ERR_DISCONNECT, "Connection reset by peer" );
- }
-
+ cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data );
if( cl_showpackets->integer ) {
- Com_Printf( "%i ", i );
+ Com_Printf( "%"PRIz" ", cursize );
}
SZ_Clear( &msg_write );
@@ -892,6 +887,7 @@ static void CL_SendBatchedCmd( void ) {
int i, j, seq, bits;
int numCmds, numDups;
int totalCmds, totalMsec;
+ size_t cursize;
usercmd_t *cmd, *oldcmd;
client_history_t *history, *oldest;
byte *patch;
@@ -962,15 +958,11 @@ static void CL_SendBatchedCmd( void ) {
//
// deliver the message
//
- i = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data );
- if( i == -1 ) {
- Com_Error( ERR_DISCONNECT, "Connection reset by peer" );
- }
-
+ cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data );
if( cl_showpackets->integer == 1 ) {
- Com_Printf( "%i(%i) ", i, totalCmds );
+ Com_Printf( "%"PRIz"(%i) ", cursize, totalCmds );
} else if( cl_showpackets->integer == 2 ) {
- Com_Printf( "%i(%i) ", i, totalMsec );
+ Com_Printf( "%"PRIz"(%i) ", cursize, totalMsec );
} else if( cl_showpackets->integer == 3 ) {
Com_Printf( " | " );
}
@@ -989,9 +981,9 @@ static void CL_SendUserinfo( void ) {
}
if( cls.userinfo_modified == MAX_PACKET_USERINFOS ) {
- i = Cvar_BitInfo( userinfo, CVAR_USERINFO );
+ size_t len = Cvar_BitInfo( userinfo, CVAR_USERINFO );
MSG_WriteByte( clc_userinfo );
- MSG_WriteData( userinfo, i + 1 );
+ MSG_WriteData( userinfo, len + 1 );
MSG_FlushTo( &cls.netchan->message );
} else if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
Com_DPrintf( "Sending %d userinfo updates at frame %u\n",
diff --git a/source/cl_locs.c b/source/cl_locs.c
index c469037..d17897a 100644
--- a/source/cl_locs.c
+++ b/source/cl_locs.c
@@ -44,13 +44,13 @@ LOC_Alloc
static location_t *LOC_Alloc( const char *name ) {
location_t *loc;
char buffer[MAX_QPATH];
- int length;
+ size_t length;
Q_ClearStr( buffer, name, sizeof( buffer ) );
length = strlen( buffer );
loc = Z_Malloc( sizeof( *loc ) + length );
- strcpy( loc->name, buffer );
+ memcpy( loc->name, buffer, length + 1 );
List_Append( &cl_locations, &loc->entry );
return loc;
@@ -214,9 +214,9 @@ void LOC_AddLocationsToScene( void ) {
LOC_Here_m
==============
*/
-static int LOC_Here_m( char *buffer, int size ) {
+static size_t LOC_Here_m( char *buffer, size_t size ) {
location_t *loc;
- int ret;
+ size_t ret;
ret = Q_strncpyz( buffer, "unknown", size );
if( cls.state != ca_active ) {
@@ -235,7 +235,7 @@ static int LOC_Here_m( char *buffer, int size ) {
LOC_There_m
==============
*/
-static int LOC_There_m( char *buffer, int size ) {
+static size_t LOC_There_m( char *buffer, size_t size ) {
location_t *loc;
vec3_t pos;
trace_t trace;
diff --git a/source/cl_main.c b/source/cl_main.c
index af3eba8..39202e8 100644
--- a/source/cl_main.c
+++ b/source/cl_main.c
@@ -1824,9 +1824,9 @@ void CL_RequestNextDownload ( void ) {
// Also check if 32bit images are present
Q_concat( fn, sizeof( fn ), "textures/", texname, ".jpg", NULL );
- if ( FS_LoadFile( fn, NULL ) == -1 ) {
+ if ( FS_LoadFile( fn, NULL ) == INVALID_LENGTH ) {
Q_concat( fn, sizeof( fn ), "textures/", texname, ".tga", NULL );
- if ( FS_LoadFile( fn, NULL ) == -1 ) {
+ if ( FS_LoadFile( fn, NULL ) == INVALID_LENGTH ) {
Q_concat( fn, sizeof( fn ), "textures/", texname, ".wal", NULL );
if ( !CL_CheckOrDownloadFile( fn ) ) {
return; // started a download
@@ -2085,21 +2085,21 @@ static void CL_Say_c( genctx_t *ctx, int argnum ) {
CL_Name_g( ctx );
}
-static int CL_Mapname_m( char *buffer, int size ) {
+static size_t CL_Mapname_m( char *buffer, size_t size ) {
if( !cl.mapname[0] ) {
return Q_strncpyz( buffer, "nomap", size );
}
return Q_strncpyz( buffer, cl.mapname, size );
}
-static int CL_Server_m( char *buffer, int size ) {
+static size_t CL_Server_m( char *buffer, size_t size ) {
if( cls.state <= ca_disconnected ) {
return Q_strncpyz( buffer, "noserver", size );
}
return Q_strncpyz( buffer, cls.servername, size );
}
-static int CL_Ups_m( char *buffer, int size ) {
+static size_t CL_Ups_m( char *buffer, size_t size ) {
vec3_t vel;
int ups;
player_state_t *ps;
@@ -2125,7 +2125,7 @@ static int CL_Ups_m( char *buffer, int size ) {
return Com_sprintf( buffer, size, "%d", ups );
}
-static int CL_Timer_m( char *buffer, int size ) {
+static size_t CL_Timer_m( char *buffer, size_t size ) {
int hour, min, sec;
sec = cl.time / 1000;
@@ -2138,19 +2138,19 @@ static int CL_Timer_m( char *buffer, int size ) {
return Com_sprintf( buffer, size, "%i:%02i", min, sec );
}
-static int CL_Fps_m( char *buffer, int size ) {
+static size_t CL_Fps_m( char *buffer, size_t size ) {
return Com_sprintf( buffer, size, "%i", cls.fps );
}
-static int CL_Ping_m( char *buffer, int size ) {
+static size_t CL_Ping_m( char *buffer, size_t size ) {
return Com_sprintf( buffer, size, "%i", cls.ping );
}
-static int CL_Health_m( char *buffer, int size ) {
+static size_t CL_Health_m( char *buffer, size_t size ) {
return Com_sprintf( buffer, size, "%i", cl.frame.ps.stats[STAT_HEALTH] );
}
-static int CL_Ammo_m( char *buffer, int size ) {
+static size_t CL_Ammo_m( char *buffer, size_t size ) {
return Com_sprintf( buffer, size, "%i", cl.frame.ps.stats[STAT_AMMO] );
}
-static int CL_Armor_m( char *buffer, int size ) {
+static size_t CL_Armor_m( char *buffer, size_t size ) {
return Com_sprintf( buffer, size, "%i", cl.frame.ps.stats[STAT_ARMOR] );
}
diff --git a/source/cl_parse.c b/source/cl_parse.c
index dbe62fe..a397ccb 100644
--- a/source/cl_parse.c
+++ b/source/cl_parse.c
@@ -77,7 +77,7 @@ qboolean CL_CheckOrDownloadFile( const char *path ) {
return qtrue;
}
- if( FS_LoadFile( filename, NULL ) != -1 ) {
+ if( FS_LoadFile( filename, NULL ) != INVALID_LENGTH ) {
// it exists, no need to download
return qtrue;
}
@@ -155,7 +155,7 @@ void CL_Download_f( void ) {
return;
}
- if( FS_LoadFile( path, NULL ) != -1 ) {
+ if( FS_LoadFile( path, NULL ) != INVALID_LENGTH ) {
Com_Printf( "File '%s' already exists.\n", path );
return;
}
@@ -593,7 +593,7 @@ static void CL_ParseFrame( int extrabits ) {
}
if( cl_shownet->integer > 2 ) {
- Com_Printf( "%3i:playerinfo\n", msg_read.readcount - 1 );
+ Com_Printf( "%3"PRIz":playerinfo\n", msg_read.readcount - 1 );
}
frame.clientNum = cl.clientNum;
@@ -634,7 +634,7 @@ static void CL_ParseFrame( int extrabits ) {
}
if( cl_shownet->integer > 2 ) {
- Com_Printf( "%3i:packetentities\n", msg_read.readcount - 1 );
+ Com_Printf( "%3"PRIz":packetentities\n", msg_read.readcount - 1 );
}
CL_ParsePacketEntities( oldframe, &frame );
@@ -648,7 +648,7 @@ static void CL_ParseFrame( int extrabits ) {
int seq = cls.netchan->incoming_acknowledged & CMD_MASK;
rtt = cls.realtime - cl.history[seq].sent;
}
- Com_Printf( "%3i: frame:%i delta:%i rtt:%i\n",
+ Com_Printf( "%3"PRIz":frame:%d delta:%d rtt:%d\n",
msg_read.readcount - 1, frame.number, frame.delta, rtt );
}
@@ -701,7 +701,7 @@ void CL_ParseClientinfo( int player ) {
static void CL_ConfigString( int index, const char *string ) {
- int length, maxlength;
+ size_t length, maxlength;
if( index >= CS_STATUSBAR && index < CS_AIRACCEL ) {
maxlength = MAX_QPATH * ( CS_AIRACCEL - index );
@@ -710,8 +710,8 @@ static void CL_ConfigString( int index, const char *string ) {
}
length = strlen( string );
if( length >= maxlength ) {
- Com_Error( ERR_DROP, "%s: index %d overflowed: %d chars",
- __func__, index, length );
+ Com_Error( ERR_DROP, "%s: index %d overflowed",
+ __func__, index );
}
memcpy( cl.configstrings[index], string, length + 1 );
@@ -1456,11 +1456,11 @@ CL_ParseServerMessage
=====================
*/
void CL_ParseServerMessage( void ) {
- int cmd, readcount;
- int extrabits;
+ int cmd, extrabits;
+ size_t readcount;
if( cl_shownet->integer == 1 ) {
- Com_Printf( "%i ", msg_read.cursize );
+ Com_Printf( "%"PRIz" ", msg_read.cursize );
} else if( cl_shownet->integer > 1 ) {
Com_Printf( "------------------\n" );
}
@@ -1477,7 +1477,7 @@ void CL_ParseServerMessage( void ) {
if( ( cmd = MSG_ReadByte() ) == -1 ) {
if( cl_shownet->integer > 1 ) {
- Com_Printf( "%3i:END OF MESSAGE\n", msg_read.readcount - 1 );
+ Com_Printf( "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1 );
}
break;
}
diff --git a/source/cmd.c b/source/cmd.c
index adb5228..970ec2b 100644
--- a/source/cmd.c
+++ b/source/cmd.c
@@ -75,7 +75,7 @@ Adds command text at the end of the buffer
============
*/
void Cbuf_AddTextEx( cmdbuf_t *buf, const char *text ) {
- int l = strlen( text );
+ size_t l = strlen( text );
if( buf->cursize + l > buf->maxsize ) {
Com_WPrintf( "Cbuf_AddText: overflow\n" );
@@ -106,7 +106,7 @@ Adds a \n to the text.
============
*/
void Cbuf_InsertTextEx( cmdbuf_t *buf, const char *text ) {
- int l = strlen( text );
+ size_t l = strlen( text );
// add the entire text of the file
if( !l ) {
@@ -255,7 +255,7 @@ char *Cmd_AliasCommand( const char *name ) {
void Cmd_AliasSet( const char *name, const char *cmd ) {
cmdalias_t *a;
unsigned hash;
- int len;
+ size_t len;
// if the alias already exists, reuse it
a = Cmd_AliasFind( name );
@@ -518,10 +518,10 @@ static char *cmd_null_string = "";
/* complete command string, quotes preserved */
static char cmd_string[MAX_STRING_CHARS];
-static int cmd_string_len;
+static size_t cmd_string_len;
/* offsets of individual tokens in cmd_string */
-static int cmd_offsets[MAX_STRING_TOKENS];
+static size_t cmd_offsets[MAX_STRING_TOKENS];
/* sequence of NULL-terminated tokens, each cmd_argv[] points here */
static char cmd_data[MAX_STRING_CHARS];
@@ -532,7 +532,7 @@ int cmd_optind;
char *cmd_optarg;
char *cmd_optopt;
-int Cmd_ArgOffset( int arg ) {
+size_t Cmd_ArgOffset( int arg ) {
if( arg < 0 ) {
return 0;
}
@@ -542,12 +542,12 @@ int Cmd_ArgOffset( int arg ) {
return cmd_offsets[arg];
}
-int Cmd_FindArgForOffset( int offset ) {
+int Cmd_FindArgForOffset( size_t offset ) {
int i;
for( i = 1; i < cmd_argc; i++ ) {
if( offset < cmd_offsets[i] ) {
- return i - 1;
+ break;
}
}
return i - 1;
@@ -661,7 +661,7 @@ char *Cmd_ArgsFrom( int from ) {
}
char *Cmd_RawArgsFrom( int from ) {
- int offset;
+ size_t offset;
if( from < 0 || from >= cmd_argc ) {
return cmd_null_string;
@@ -843,7 +843,8 @@ Cmd_MacroExpandString
======================
*/
char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) {
- int i, j, count, len;
+ size_t i, j, len;
+ int count;
qboolean inquote;
char *scan, *start;
static char expanded[MAX_STRING_CHARS];
@@ -1427,7 +1428,7 @@ static void Cmd_Complete_f( void ) {
cmd_function_t *cmd;
char *name;
unsigned hash;
- int len;
+ size_t len;
if( cmd_argc < 2 ) {
Com_Printf( "Usage: %s <command>", cmd_argv[0] );
diff --git a/source/cmodel.c b/source/cmodel.c
index 91e562d..d65ca67 100644
--- a/source/cmodel.c
+++ b/source/cmodel.c
@@ -38,13 +38,13 @@ void CM_FloodAreaConnections( cm_t *cm );
typedef struct {
void *base;
- unsigned count;
+ size_t count;
} cmlump_t;
typedef struct {
size_t size;
- unsigned mincount;
- unsigned maxcount;
+ size_t mincount;
+ size_t maxcount;
const char *name;
} lump_info_t;
@@ -684,7 +684,7 @@ const char *CM_LoadMapEx( cm_t *cm, const char *name, int flags, uint32_t *check
cmlump_t *out;
const lump_info_t *info;
const lump_load_t *load;
- unsigned length, endpos, fileofs, filelen;
+ size_t length, endpos, fileofs, filelen;
char *error;
// char *entstring;
// char buffer[MAX_QPATH];
diff --git a/source/com_local.h b/source/com_local.h
index 81fb2bb..d7b0a2c 100644
--- a/source/com_local.h
+++ b/source/com_local.h
@@ -52,8 +52,8 @@ Command text buffering and command execution
typedef struct {
char *text; // may not be NULL terminated
- int cursize;
- int maxsize;
+ size_t cursize;
+ size_t maxsize;
int waitCount;
int aliasCount; // for detecting runaway loops
void (*exec)( const char * );
@@ -175,8 +175,8 @@ char *Cmd_ArgsFrom( int from );
char *Cmd_RawArgsFrom( int from );
void Cmd_ArgsBuffer( char *buffer, int bufferSize );
void Cmd_ArgvBuffer( int arg, char *buffer, int bufferSize );
-int Cmd_ArgOffset( int arg );
-int Cmd_FindArgForOffset( int offset );
+size_t Cmd_ArgOffset( int arg );
+int Cmd_FindArgForOffset( size_t offset );
char *Cmd_RawString( void );
void Cmd_Shift( void );
// The functions that execute commands get their parameters with these
@@ -279,7 +279,7 @@ void Cvar_WriteVariables( fileHandle_t f, int mask, qboolean modified );
void Cvar_Init (void);
-int Cvar_BitInfo( char *info, int bit );
+size_t Cvar_BitInfo( char *info, int bit );
cvar_t *Cvar_ForceSetEx( const char *var_name, const char *value, int flags );
@@ -325,12 +325,12 @@ FIFO
typedef struct {
byte *data;
- int size;
- int ax, ay, bs;
+ size_t size;
+ size_t ax, ay, bs;
} fifo_t;
-static inline void *FIFO_Reserve( fifo_t *fifo, int *reserved ) {
- int tail;
+static inline void *FIFO_Reserve( fifo_t *fifo, size_t *reserved ) {
+ size_t tail;
if( fifo->bs ) {
*reserved = fifo->ax - fifo->bs;
@@ -347,31 +347,31 @@ static inline void *FIFO_Reserve( fifo_t *fifo, int *reserved ) {
return fifo->data;
}
-static inline void FIFO_Commit( fifo_t *fifo, int length ) {
- int tail;
+static inline void FIFO_Commit( fifo_t *fifo, size_t len ) {
+ size_t tail;
if( fifo->bs ) {
- fifo->bs += length;
+ fifo->bs += len;
return;
}
tail = fifo->size - fifo->ay;
if( fifo->ax < tail ) {
- fifo->ay += length;
+ fifo->ay += len;
return;
}
- fifo->bs = length;
+ fifo->bs = len;
}
-static inline void *FIFO_Peek( fifo_t *fifo, int *length ) {
- *length = fifo->ay - fifo->ax;
+static inline void *FIFO_Peek( fifo_t *fifo, size_t *len ) {
+ *len = fifo->ay - fifo->ax;
return fifo->data + fifo->ax;
}
-static inline void FIFO_Decommit( fifo_t *fifo, int length ) {
- if( fifo->ax + length < fifo->ay ) {
- fifo->ax += length;
+static inline void FIFO_Decommit( fifo_t *fifo, size_t len ) {
+ if( fifo->ax + len < fifo->ay ) {
+ fifo->ax += len;
return;
}
@@ -379,37 +379,37 @@ static inline void FIFO_Decommit( fifo_t *fifo, int length ) {
fifo->ax = fifo->bs = 0;
}
+static inline size_t FIFO_Usage( fifo_t *fifo ) {
+ return fifo->ay - fifo->ax + fifo->bs;
+}
+
static inline int FIFO_Percent( fifo_t *fifo ) {
if( !fifo->size ) {
return 0;
}
- return ( fifo->ay - fifo->ax + fifo->bs ) * 100 / fifo->size;
-}
-
-static inline int FIFO_Usage( fifo_t *fifo ) {
- return fifo->ay - fifo->ax + fifo->bs;
+ return ( int )( FIFO_Usage( fifo ) * 100 / fifo->size );
}
static inline void FIFO_Clear( fifo_t *fifo ) {
fifo->ax = fifo->ay = fifo->bs = 0;
}
-int FIFO_Read( fifo_t *fifo, void *buffer, int length );
-int FIFO_Write( fifo_t *fifo, const void *buffer, int length );
+size_t FIFO_Read( fifo_t *fifo, void *buffer, size_t len );
+size_t FIFO_Write( fifo_t *fifo, const void *buffer, size_t len );
-static inline qboolean FIFO_TryRead( fifo_t *fifo, void *buffer, int length ) {
- if( FIFO_Read( fifo, NULL, length ) < length ) {
+static inline qboolean FIFO_TryRead( fifo_t *fifo, void *buffer, size_t len ) {
+ if( FIFO_Read( fifo, NULL, len ) < len ) {
return qfalse;
}
- FIFO_Read( fifo, buffer, length );
+ FIFO_Read( fifo, buffer, len );
return qtrue;
}
-static inline qboolean FIFO_TryWrite( fifo_t *fifo, void *buffer, int length ) {
- if( FIFO_Write( fifo, NULL, length ) < length ) {
+static inline qboolean FIFO_TryWrite( fifo_t *fifo, void *buffer, size_t len ) {
+ if( FIFO_Write( fifo, NULL, len ) < len ) {
return qfalse;
}
- FIFO_Write( fifo, buffer, length );
+ FIFO_Write( fifo, buffer, len );
return qtrue;
}
@@ -534,7 +534,7 @@ void NET_Config( netflag_t flag );
qboolean NET_GetAddress( netsrc_t sock, netadr_t *adr );
neterr_t NET_GetPacket( netsrc_t sock );
-neterr_t NET_SendPacket( netsrc_t sock, const netadr_t *to, unsigned length, const void *data );
+neterr_t NET_SendPacket( netsrc_t sock, const netadr_t *to, size_t length, const void *data );
qboolean NET_GetLoopPacket( netsrc_t sock );
char * NET_AdrToString( const netadr_t *a );
@@ -586,7 +586,7 @@ typedef enum netchan_type_e {
typedef struct netchan_s {
netchan_type_t type;
int protocol;
- int maxpacketlen;
+ size_t maxpacketlen;
qboolean fatal_error;
@@ -602,7 +602,7 @@ typedef struct netchan_s {
sizebuf_t message; // writing buffer for reliable data
- int reliable_length;
+ size_t reliable_length;
qboolean reliable_ack_pending; // set to qtrue each time reliable is received
qboolean fragment_pending;
@@ -612,8 +612,8 @@ typedef struct netchan_s {
int incoming_acknowledged;
int outgoing_sequence;
- int (*Transmit)( struct netchan_s *, int, const byte * );
- int (*TransmitNextFragment)( struct netchan_s * );
+ size_t (*Transmit)( struct netchan_s *, size_t, const void * );
+ size_t (*TransmitNextFragment)( struct netchan_s * );
qboolean (*Process)( struct netchan_s * );
qboolean (*ShouldUpdate)( struct netchan_s * );
} netchan_t;
@@ -625,12 +625,10 @@ extern cvar_t *net_maxmsglen;
extern cvar_t *net_chantype;
void Netchan_Init( void );
-neterr_t Netchan_OutOfBand( netsrc_t sock, const netadr_t *adr, unsigned length,
- const byte *data );
neterr_t Netchan_OutOfBandPrint( netsrc_t sock, const netadr_t *adr,
const char *format, ... );
netchan_t *Netchan_Setup( netsrc_t sock, netchan_type_t type,
- const netadr_t *adr, int qport, int maxpacketlen, int protocol );
+ const netadr_t *adr, int qport, size_t maxpacketlen, int protocol );
void Netchan_Close( netchan_t *netchan );
#define OOB_PRINT( sock, addr, string ) \
@@ -860,35 +858,34 @@ qboolean FS_RenameFile( const char *from, const char *to );
char *FS_CopyExtraInfo( const char *name, const fsFileInfo_t *info );
-int FS_FOpenFile( const char *filename, fileHandle_t *f, int mode );
+size_t FS_FOpenFile( const char *filename, fileHandle_t *f, int mode );
void FS_FCloseFile( fileHandle_t hFile );
-int FS_LoadFile( const char *path, void **buffer );
-int FS_LoadFileEx( const char *path, void **buffer, int flags );
-void *FS_AllocTempMem( int length );
+size_t FS_LoadFile( const char *path, void **buffer );
+size_t FS_LoadFileEx( const char *path, void **buffer, int flags );
+void *FS_AllocTempMem( size_t length );
void FS_FreeFile( void *buffer );
// a null buffer will just return the file length without loading
// a -1 length is not present
-int FS_Read( void *buffer, int len, fileHandle_t hFile );
-int FS_Write( const void *buffer, int len, fileHandle_t hFile );
+size_t FS_Read( void *buffer, size_t len, fileHandle_t hFile );
+size_t FS_Write( const void *buffer, size_t len, fileHandle_t hFile );
// properly handles partial reads
void FS_FPrintf( fileHandle_t f, const char *format, ... ) q_printf( 2, 3 );
-int FS_ReadLine( fileHandle_t f, char *buffer, int size );
+size_t FS_ReadLine( fileHandle_t f, char *buffer, int size );
int FS_Tell( fileHandle_t f );
int FS_RawTell( fileHandle_t f );
-int FS_GetFileLength( fileHandle_t f );
-int FS_GetFileLengthNoCache( fileHandle_t f );
+size_t FS_GetFileLength( fileHandle_t f );
qboolean FS_WildCmp( const char *filter, const char *string );
qboolean FS_ExtCmp( const char *extension, const char *string );
void **FS_ListFiles( const char *path, const char *extension, int flags, int *numFiles );
void **FS_CopyList( void **list, int count );
-fsFileInfo_t *FS_CopyInfo( const char *name, int size, time_t ctime, time_t mtime );
+fsFileInfo_t *FS_CopyInfo( const char *name, size_t size, time_t ctime, time_t mtime );
void FS_FreeList( void **list );
qboolean FS_LastFileFromPak( void );
@@ -933,9 +930,9 @@ typedef struct string_entry_s {
char string[1];
} string_entry_t;
-typedef void (*rdflush_t)( int target, char *buffer, int length );
+typedef void (*rdflush_t)( int target, char *buffer, size_t len );
-void Com_BeginRedirect (int target, char *buffer, int buffersize, rdflush_t flush);
+void Com_BeginRedirect (int target, char *buffer, size_t buffersize, rdflush_t flush);
void Com_EndRedirect (void);
void Com_LevelPrint( comPrintType_t type, const char *str );
@@ -945,7 +942,7 @@ void Com_FillAPI( commonAPI_t *api );
void Com_Quit (void);
-byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence);
+byte COM_BlockSequenceCRCByte (byte *base, size_t length, int sequence);
void Com_ProcessEvents( void );
@@ -955,10 +952,10 @@ void Com_Generic_c( genctx_t *ctx, int argnum );
qboolean Prompt_AddMatch( genctx_t *ctx, const char *s );
qboolean Prompt_AddMatchCase( genctx_t *ctx, const char *s );
-int Com_Time_m( char *buffer, int size );
-int Com_Uptime_m( char *buffer, int size );
+size_t Com_Time_m( char *buffer, size_t size );
+size_t Com_Uptime_m( char *buffer, size_t size );
-uint32_t Com_BlockChecksum( void *buffer, int length );
+uint32_t Com_BlockChecksum( void *buffer, size_t len );
// may return pointer to static memory
@@ -1053,7 +1050,7 @@ void Sys_SetConsoleTitle( const char *title );
void Sys_Error( const char *error, ... ) q_noreturn q_printf( 1, 2 );
void Sys_Quit( void );
-void **Sys_ListFiles( const char *path, const char *extension, int flags, int length, int *numFiles );
+void **Sys_ListFiles( const char *path, const char *extension, int flags, size_t length, int *numFiles );
qboolean Sys_Mkdir( const char *path );
qboolean Sys_RemoveFile( const char *path );
diff --git a/source/com_public.h b/source/com_public.h
index 892fcfa..b446baf 100644
--- a/source/com_public.h
+++ b/source/com_public.h
@@ -38,12 +38,12 @@ typedef enum cbufExecWhen_e {
} cbufExecWhen_t;
typedef void ( *xcommand_t )( void );
-typedef int ( *xmacro_t )( char *, int );
+typedef size_t ( *xmacro_t )( char *, size_t );
typedef void ( *xcompleter_t )( struct genctx_s *, int );
typedef struct genctx_s {
const char *partial;
- int length;
+ size_t length;
int argnum;
char **matches;
int count, size;
@@ -117,7 +117,7 @@ FILESYSTEM
#define MAX_LISTED_FILES 4096
typedef struct fsFileInfo_s {
- int size;
+ size_t size;
time_t ctime;
time_t mtime;
char name[1];
@@ -166,18 +166,20 @@ typedef struct fsFileInfo_s {
#define FS_FLAG_RAW 0x00000080
#define FS_FLAG_CACHE 0x00000100
+#define INVALID_LENGTH ( ( size_t )-1 )
+
typedef struct fsAPI_s {
void (*FCloseFile)( fileHandle_t f );
- int (*Read)( void *buffer, int len, fileHandle_t f );
- int (*Write)( const void *buffer, int len, fileHandle_t f );
- int (*FOpenFile)( const char *filename, fileHandle_t *f, int mode );
+ size_t (*Read)( void *buffer, size_t len, fileHandle_t f );
+ size_t (*Write)( const void *buffer, size_t len, fileHandle_t f );
+ size_t (*FOpenFile)( const char *filename, fileHandle_t *f, int mode );
void (*FPrintf)( fileHandle_t f, const char *format, ... );
- int (*ReadLine)( fileHandle_t f, char *buffer, int size );
+ size_t (*ReadLine)( fileHandle_t f, char *buffer, int size );
int (*Tell)( fileHandle_t f );
int (*RawTell)( fileHandle_t f );
- int (*LoadFile)( const char *path, void **buffer );
- int (*LoadFileEx)( const char *path, void **buffer, int flags );
- void *(*AllocTempMem)( int length );
+ size_t (*LoadFile)( const char *path, void **buffer );
+ size_t (*LoadFileEx)( const char *path, void **buffer, int flags );
+ void *(*AllocTempMem)( size_t length );
void (*FreeFile)( void *buffer );
void **(*ListFiles)( const char *path, const char *extension, int flags, int *numFiles );
void (*FreeList)( void **list );
@@ -264,7 +266,7 @@ MODULES
*/
// if api_version is different, the dll cannot be used
-#define MODULES_APIVERSION 314
+#define MODULES_APIVERSION 315
typedef enum moduleQuery_e {
MQ_GETINFO,
diff --git a/source/common.c b/source/common.c
index f2a95bf..f49b4cd 100644
--- a/source/common.c
+++ b/source/common.c
@@ -86,11 +86,11 @@ CLIENT / SERVER interactions
static int rd_target;
static char *rd_buffer;
-static int rd_buffersize;
-static int rd_length;
+static size_t rd_buffersize;
+static size_t rd_length;
static rdflush_t rd_flush;
-void Com_BeginRedirect( int target, char *buffer, int buffersize, rdflush_t flush ) {
+void Com_BeginRedirect( int target, char *buffer, size_t buffersize, rdflush_t flush ) {
if( rd_target || !target || !buffer || buffersize < 1 || !flush ) {
return;
}
@@ -121,8 +121,8 @@ void Com_EndRedirect( void ) {
rd_length = 0;
}
-static void Com_Redirect( const char *msg, int total ) {
- int length;
+static void Com_Redirect( const char *msg, size_t total ) {
+ size_t length;
while( total ) {
length = total;
@@ -194,7 +194,7 @@ static void LogFile_Output( const char *string ) {
char text[MAXPRINTMSG];
char timebuf[MAX_QPATH];
char *p, *maxp;
- int length;
+ size_t length;
time_t clock;
struct tm *tm;
int c;
@@ -253,7 +253,7 @@ void Com_Printf( const char *fmt, ... ) {
va_list argptr;
char msg[MAXPRINTMSG];
static int recursive;
- int length;
+ size_t len;
if( recursive == 2 ) {
return;
@@ -262,11 +262,11 @@ void Com_Printf( const char *fmt, ... ) {
recursive++;
va_start( argptr, fmt );
- length = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
+ len = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
va_end( argptr );
if( rd_target ) {
- Com_Redirect( msg, length );
+ Com_Redirect( msg, len );
} else {
// graphical console
Con_Print( msg );
@@ -487,11 +487,13 @@ static zhead_t z_chain;
static cvar_t *z_perturb;
+#pragma pack( push, 1 )
typedef struct {
zhead_t z;
char data[2];
uint16_t tail;
-} q_packed zstatic_t;
+} zstatic_t;
+#pragma pack( pop )
#define Z_STATIC( x ) { { Z_MAGIC, TAG_STATIC, sizeof( zstatic_t ) }, x, Z_TAIL }
@@ -567,7 +569,7 @@ void Z_LeakTest( memtag_t tag ) {
if( numLeaks ) {
Com_Printf( S_COLOR_YELLOW "************* Z_LeakTest *************\n"
- "%s leaked %"PRIz"u bytes of memory (%"PRIz"u object%s)\n"
+ "%s leaked %"PRIz" bytes of memory (%"PRIz"u object%s)\n"
"**************************************\n",
z_tagnames[tag < TAG_MAX ? tag : TAG_FREE],
numBytes, numLeaks, numLeaks == 1 ? "" : "s" );
@@ -636,7 +638,7 @@ void *Z_Realloc( void *ptr, size_t size ) {
z = realloc( z, size );
if( !z ) {
- Com_Error( ERR_FATAL, "Z_Realloc: couldn't realloc %"PRIz"u bytes", size );
+ Com_Error( ERR_FATAL, "Z_Realloc: couldn't realloc %"PRIz" bytes", size );
}
z->size = size;
@@ -667,13 +669,13 @@ void Z_Stats_f( void ) {
if( !s->count ) {
continue;
}
- Com_Printf( "%9"PRIz"u %6"PRIz"u %s\n", s->bytes, s->count, z_tagnames[i] );
+ Com_Printf( "%9"PRIz" %6"PRIz" %s\n", s->bytes, s->count, z_tagnames[i] );
bytes += s->bytes;
count += s->count;
}
Com_Printf( "--------- ------ -------\n"
- "%9"PRIz"u %6"PRIz"u total\n",
+ "%9"PRIz" %6"PRIz" total\n",
bytes, count );
}
@@ -714,14 +716,20 @@ void *Z_TagMalloc( size_t size, memtag_t tag ) {
size = ( size + 3 ) & ~3;
z = malloc( size );
if( !z ) {
- Com_Error( ERR_FATAL, "Z_TagMalloc: couldn't allocate %"PRIz"u bytes", size );
+ Com_Error( ERR_FATAL, "Z_TagMalloc: couldn't allocate %"PRIz" bytes", size );
}
z->magic = Z_MAGIC;
z->tag = tag;
z->size = size;
#ifdef _DEBUG
+#if( defined __GNUC__ )
z->addr = __builtin_return_address( 0 );
+#elif( defined _MSC_VER )
+ z->addr = _ReturnAddress();
+#else
+ z->addr = NULL;
+#endif
#endif
z->next = z_chain.next;
@@ -781,7 +789,7 @@ void *Z_ReservedAllocz( size_t size ) {
}
char *Z_ReservedCopyString( const char *in ) {
- int len;
+ size_t len;
if( !in ) {
return NULL;
@@ -806,7 +814,7 @@ Z_TagCopyString
================
*/
char *Z_TagCopyString( const char *in, memtag_t tag ) {
- int len;
+ size_t len;
if( !in ) {
return NULL;
@@ -822,7 +830,7 @@ Cvar_CopyString
================
*/
char *Cvar_CopyString( const char *in ) {
- int len;
+ size_t len;
zstatic_t *z;
if( !in ) {
@@ -855,18 +863,18 @@ char *Cvar_CopyString( const char *in ) {
==============================================================================
*/
-int FIFO_Read( fifo_t *fifo, void *buffer, int length ) {
- int head = fifo->ay - fifo->ax;
- int wrapped = length - head;
+size_t FIFO_Read( fifo_t *fifo, void *buffer, size_t len ) {
+ size_t wrapped, head = fifo->ay - fifo->ax;
- if( wrapped < 0 ) {
+ if( head > len ) {
if( buffer ) {
- memcpy( buffer, fifo->data + fifo->ax, length );
- fifo->ax += length;
+ memcpy( buffer, fifo->data + fifo->ax, len );
+ fifo->ax += len;
}
- return length;
+ return len;
}
+ wrapped = len - head;
if( wrapped > fifo->bs ) {
wrapped = fifo->bs;
}
@@ -881,32 +889,31 @@ int FIFO_Read( fifo_t *fifo, void *buffer, int length ) {
return head + wrapped;
}
-int FIFO_Write( fifo_t *fifo, const void *buffer, int length ) {
- int tail, wrapped, remaining;
+size_t FIFO_Write( fifo_t *fifo, const void *buffer, size_t len ) {
+ size_t tail, wrapped, remaining;
if( fifo->bs ) {
remaining = fifo->ax - fifo->bs;
- if( length > remaining ) {
- length = remaining;
+ if( len > remaining ) {
+ len = remaining;
}
if( buffer ) {
- memcpy( fifo->data + fifo->bs, buffer, length );
- fifo->bs += length;
+ memcpy( fifo->data + fifo->bs, buffer, len );
+ fifo->bs += len;
}
- return length;
+ return len;
}
tail = fifo->size - fifo->ay;
- wrapped = length - tail;
-
- if( wrapped < 0 ) {
+ if( tail > len ) {
if( buffer ) {
- memcpy( fifo->data + fifo->ay, buffer, length );
- fifo->ay += length;
+ memcpy( fifo->data + fifo->ay, buffer, len );
+ fifo->ay += len;
}
- return length;
+ return len;
}
+ wrapped = len - tail;
if( wrapped > fifo->ax ) {
wrapped = fifo->ax;
}
@@ -946,7 +953,7 @@ void Com_FillAPI( commonAPI_t *api ) {
Com_Time_m
=============
*/
-int Com_Time_m( char *buffer, int size ) {
+size_t Com_Time_m( char *buffer, size_t size ) {
time_t clock;
struct tm *local;
@@ -961,7 +968,7 @@ int Com_Time_m( char *buffer, int size ) {
Com_Date_m
=============
*/
-static int Com_Date_m( char *buffer, int size ) {
+static size_t Com_Date_m( char *buffer, size_t size ) {
time_t clock;
struct tm *local;
@@ -971,7 +978,7 @@ static int Com_Date_m( char *buffer, int size ) {
return strftime( buffer, size, com_date_format->string, local );
}
-int Com_Uptime_m( char *buffer, int size ) {
+size_t Com_Uptime_m( char *buffer, size_t size ) {
int sec, min, hour, day;
time_t clock;
@@ -993,7 +1000,7 @@ int Com_Uptime_m( char *buffer, int size ) {
return Com_sprintf( buffer, size, "%02d.%02d", min, sec );
}
-int Com_Random_m( char *buffer, int size ) {
+size_t Com_Random_m( char *buffer, size_t size ) {
return Com_sprintf( buffer, size, "%d", ( rand() ^ ( rand() >> 8 ) ) % 10 );
}
diff --git a/source/crc.c b/source/crc.c
index 8c8ee3c..50979fc 100644
--- a/source/crc.c
+++ b/source/crc.c
@@ -28,8 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define CRC_INIT_VALUE 0xffff
#define CRC_XOR_VALUE 0x0000
-static unsigned short crctable[256] =
-{
+static const uint16_t crctable[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
@@ -64,33 +63,16 @@ static unsigned short crctable[256] =
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
-void CRC_Init(unsigned short *crcvalue)
-{
- *crcvalue = CRC_INIT_VALUE;
-}
-
-void CRC_ProcessByte(unsigned short *crcvalue, byte data)
-{
- *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
-}
+static uint16_t CRC_Block (byte *start, size_t count) {
+ uint16_t crc = CRC_INIT_VALUE;
-unsigned short CRC_Value(unsigned short crcvalue)
-{
- return crcvalue ^ CRC_XOR_VALUE;
-}
-
-unsigned short CRC_Block (byte *start, int count)
-{
- unsigned short crc;
-
- CRC_Init (&crc);
while (count--)
crc = (crc << 8) ^ crctable[(crc >> 8) ^ *start++];
return crc;
}
-static byte chktbl[1024] = {
+static const byte chktbl[1024] = {
0x84, 0x47, 0x51, 0xc1, 0x93, 0x22, 0x21, 0x24, 0x2f, 0x66, 0x60, 0x4d, 0xb0, 0x7c, 0xda,
0x88, 0x54, 0x15, 0x2b, 0xc6, 0x6c, 0x89, 0xc5, 0x9d, 0x48, 0xee, 0xe6, 0x8a, 0xb5, 0xf4,
0xcb, 0xfb, 0xf1, 0x0c, 0x2e, 0xa0, 0xd7, 0xc9, 0x1f, 0xd6, 0x06, 0x9a, 0x09, 0x41, 0x54,
@@ -164,17 +146,15 @@ COM_BlockSequenceCRCByte
For proxy protecting
====================
*/
-byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence)
-{
+byte COM_BlockSequenceCRCByte (byte *base, size_t length, int sequence) {
int n;
- byte *p;
+ const byte *p;
int x;
byte chkb[60 + 4];
unsigned short crc;
-
if (sequence < 0)
- Com_Error(ERR_FATAL, "sequence < 0, this shouldn't happen\n");
+ Com_Error(ERR_DROP, "%s: sequence < 0", __func__);
p = chktbl + (sequence % (sizeof(chktbl) - 4));
diff --git a/source/cvar.c b/source/cvar.c
index b78828e..79df3f0 100644
--- a/source/cvar.c
+++ b/source/cvar.c
@@ -174,7 +174,7 @@ The flags will be or'ed in if the variable exists.
cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
cvar_t *var, *c, **p;
unsigned hash;
- int length;
+ size_t length;
if( !var_name ) {
Com_Error( ERR_FATAL, "Cvar_Get: NULL var_name" );
@@ -1035,10 +1035,10 @@ static void Cvar_Reset_c( genctx_t *ctx, int argnum ) {
}
}
-int Cvar_BitInfo( char *info, int bit ) {
+size_t Cvar_BitInfo( char *info, int bit ) {
char newi[MAX_INFO_STRING];
cvar_t *var;
- int length, total = 0;
+ size_t length, total = 0;
for( var = cvar_vars; var; var = var->next ) {
if( !( var->flags & bit ) ) {
diff --git a/source/files.c b/source/files.c
index f1a1f06..a698d6d 100644
--- a/source/files.c
+++ b/source/files.c
@@ -61,8 +61,8 @@ QUAKE FILESYSTEM
typedef struct packfile_s {
char *name;
- int filepos;
- int filelen;
+ size_t filepos;
+ size_t filelen;
struct packfile_s *hashNext;
} packfile_t;
@@ -106,12 +106,12 @@ typedef struct fsFile_s {
#endif
packfile_t *pak;
qboolean unique;
- int length;
+ size_t length;
} fsFile_t;
typedef struct fsLink_s {
char *target;
- int targetLength, nameLength;
+ size_t targlen, namelen;
struct fsLink_s *next;
char name[1];
} fsLink_t;
@@ -315,39 +315,14 @@ Returns cached length for files opened for reading.
Returns compressed length for GZIP files.
================
*/
-int FS_GetFileLength( fileHandle_t f ) {
- fsFile_t *file = FS_FileForHandle( f );
- fsFileInfo_t info;
-
-#if USE_ZLIB
- if( file->type == FS_GZIP ) {
- return -1;
- }
-#endif
-
- if( ( file->mode & FS_MODE_MASK ) == FS_MODE_READ ) {
- return file->length;
- }
-
- if( file->type != FS_REAL ) {
- Com_Error( ERR_FATAL, "%s: bad file type", __func__ );
- }
-
- if( !Sys_GetFileInfo( file->fp, &info ) ) {
- return -1;
- }
-
- return info.size;
-}
-
-int FS_GetFileLengthNoCache( fileHandle_t f ) {
+size_t FS_GetFileLength( fileHandle_t f ) {
fsFile_t *file = FS_FileForHandle( f );
fsFileInfo_t info;
switch( file->type ) {
case FS_REAL:
if( !Sys_GetFileInfo( file->fp, &info ) ) {
- return -1;
+ return INVALID_LENGTH;
}
return info.size;
case FS_PAK:
@@ -356,13 +331,13 @@ int FS_GetFileLengthNoCache( fileHandle_t f ) {
case FS_PK2:
return file->length;
case FS_GZIP:
- return -1;
+ return INVALID_LENGTH;
+#endif
default:
Com_Error( ERR_FATAL, "%s: bad file type", __func__ );
-#endif
}
- return -1;
+ return INVALID_LENGTH;
}
const char *FS_GetFileFullPath( fileHandle_t f ) {
@@ -449,7 +424,7 @@ FS_FOpenFileWrite
In case of GZIP files, returns *raw* (compressed) length!
============
*/
-static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) {
+static size_t FS_FOpenFileWrite( fsFile_t *file, const char *name ) {
FILE *fp;
#if USE_ZLIB
gzFile zfp;
@@ -458,6 +433,7 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) {
char *modeStr;
fsFileType_t type;
unsigned mode;
+
#ifdef _WIN32
// allow writing into basedir on Windows
if( ( file->mode & FS_PATH_MASK ) == FS_PATH_BASE ) {
@@ -496,7 +472,7 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) {
if( !fp ) {
FS_DPrintf( "%s: %s: fopen(%s): %s\n",
__func__, file->fullpath, modeStr, strerror( errno ) );
- return -1;
+ return INVALID_LENGTH;
}
#ifdef __unix__
@@ -504,7 +480,7 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) {
FS_DPrintf( "%s: %s: couldn't get info\n",
__func__, file->fullpath );
fclose( fp );
- return -1;
+ return INVALID_LENGTH;
}
#endif
@@ -518,7 +494,7 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) {
FS_DPrintf( "%s: %s: gzdopen(%s): %s\n",
__func__, file->fullpath, modeStr, strerror( errno ) );
fclose( fp );
- return -1;
+ return INVALID_LENGTH;
}
file->zfp = zfp;
type = FS_GZIP;
@@ -541,7 +517,7 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) {
fseek( fp, 0, SEEK_END );
}
- return ftell( fp );
+ return ( size_t )ftell( fp );
}
static searchpath_t *FS_SearchPath( unsigned flags ) {
@@ -563,7 +539,7 @@ Used for streaming data out of either a pak file or
a seperate file.
===========
*/
-static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique ) {
+static size_t FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique ) {
searchpath_t *search;
pack_t *pak;
unsigned hash;
@@ -688,7 +664,7 @@ static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique )
FS_DPrintf( "%s: %s: gzdopen(rb): %s\n",
__func__, file->fullpath, strerror( errno ) );
fclose( fp );
- return -1;
+ continue;
}
file->zfp = zfp;
type = FS_GZIP;
@@ -708,7 +684,7 @@ static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique )
FS_DPrintf( "%s: %s: not found\n", __func__, name );
- return -1;
+ return INVALID_LENGTH;
}
/*
@@ -728,9 +704,8 @@ FS_ReadFile
Properly handles partial reads
=================
*/
-int FS_Read( void *buffer, int len, fileHandle_t hFile ) {
- int block, remaining = len;
- int read = 0;
+size_t FS_Read( void *buffer, size_t len, fileHandle_t hFile ) {
+ size_t block, remaining = len, read = 0;
byte *buf = (byte *)buffer;
fsFile_t *file = FS_FileForHandle( hFile );
@@ -758,8 +733,8 @@ int FS_Read( void *buffer, int len, fileHandle_t hFile ) {
if( read == 0 ) {
return len - remaining;
}
- if( read == -1 ) {
- Com_Error( ERR_FATAL, "FS_Read: -1 bytes read" );
+ if( read > block ) {
+ Com_Error( ERR_FATAL, "FS_Read: %"PRIz" bytes read", read );
}
remaining -= read;
@@ -769,10 +744,10 @@ int FS_Read( void *buffer, int len, fileHandle_t hFile ) {
return len;
}
-int FS_ReadLine( fileHandle_t f, char *buffer, int size ) {
+size_t FS_ReadLine( fileHandle_t f, char *buffer, int size ) {
fsFile_t *file = FS_FileForHandle( f );
char *s;
- int len;
+ size_t len;
if( file->type != FS_REAL ) {
return 0;
@@ -797,9 +772,8 @@ FS_Write
Properly handles partial writes
=================
*/
-int FS_Write( const void *buffer, int len, fileHandle_t hFile ) {
- int block, remaining = len;
- int write = 0;
+size_t FS_Write( const void *buffer, size_t len, fileHandle_t hFile ) {
+ size_t block, remaining = len, write = 0;
byte *buf = (byte *)buffer;
fsFile_t *file = FS_FileForHandle( hFile );
@@ -824,8 +798,8 @@ int FS_Write( const void *buffer, int len, fileHandle_t hFile ) {
if( write == 0 ) {
return len - remaining;
}
- if( write == -1 ) {
- Com_Error( ERR_FATAL, "FS_Write: -1 bytes written" );
+ if( write > block ) {
+ Com_Error( ERR_FATAL, "FS_Write: %"PRIz" bytes written", write );
}
remaining -= write;
@@ -853,21 +827,21 @@ int FS_Write( const void *buffer, int len, fileHandle_t hFile ) {
static char *FS_ExpandLinks( const char *filename ) {
static char buffer[MAX_OSPATH];
fsLink_t *l;
- int length;
+ size_t length;
length = strlen( filename );
for( l = fs_links; l; l = l->next ) {
- if( l->nameLength > length ) {
+ if( l->namelen > length ) {
continue;
}
- if( !Q_stricmpn( l->name, filename, l->nameLength ) ) {
- if( l->targetLength + length - l->nameLength >= MAX_OSPATH ) {
+ if( !Q_stricmpn( l->name, filename, l->namelen ) ) {
+ if( l->targlen + length - l->namelen >= MAX_OSPATH ) {
FS_DPrintf( "%s: %s: MAX_OSPATH exceeded\n", __func__, filename );
return ( char * )filename;
}
- memcpy( buffer, l->target, l->targetLength );
- memcpy( buffer + l->targetLength, filename + l->nameLength,
- length - l->nameLength + 1 );
+ memcpy( buffer, l->target, l->targlen );
+ memcpy( buffer + l->targlen, filename + l->namelen,
+ length - l->namelen + 1 );
FS_DPrintf( "%s: %s --> %s\n", __func__, filename, buffer );
return buffer;
}
@@ -881,10 +855,10 @@ static char *FS_ExpandLinks( const char *filename ) {
FS_FOpenFile
============
*/
-int FS_FOpenFile( const char *name, fileHandle_t *f, int mode ) {
+size_t FS_FOpenFile( const char *name, fileHandle_t *f, int mode ) {
fsFile_t *file;
fileHandle_t hFile;
- int ret = -1;
+ size_t ret = INVALID_LENGTH;
if( !name || !f ) {
Com_Error( ERR_FATAL, "FS_FOpenFile: NULL" );
@@ -893,7 +867,7 @@ int FS_FOpenFile( const char *name, fileHandle_t *f, int mode ) {
*f = 0;
if( !fs_searchpaths ) {
- return -1; // not yet initialized
+ return ret; // not yet initialized
}
if( *name == '/' ) {
@@ -906,7 +880,7 @@ int FS_FOpenFile( const char *name, fileHandle_t *f, int mode ) {
if( !FS_ValidatePath( name ) ) {
FS_DPrintf( "FS_FOpenFile: refusing invalid path: %s\n", name );
- return -1;
+ return ret;
}
// allocate new file handle
@@ -1007,8 +981,8 @@ int FS_RawTell( fileHandle_t f ) {
// the last allocation may be easily undone
static byte loadBuffer[MAX_LOAD_BUFFER];
static byte *loadLast;
-static int loadSaved;
-static int loadInuse;
+static size_t loadSaved;
+static size_t loadInuse;
static int loadStack;
// for statistics
@@ -1023,11 +997,11 @@ Filenames are relative to the quake search path
a null buffer will just return the file length without loading
============
*/
-int FS_LoadFileEx( const char *path, void **buffer, int flags ) {
+size_t FS_LoadFileEx( const char *path, void **buffer, int flags ) {
fsFile_t *file;
fileHandle_t f;
byte *buf;
- int length;
+ size_t length;
if( !path ) {
Com_Error( ERR_FATAL, "FS_LoadFile: NULL" );
@@ -1038,7 +1012,7 @@ int FS_LoadFileEx( const char *path, void **buffer, int flags ) {
}
if( !fs_searchpaths ) {
- return -1; // not yet initialized
+ return INVALID_LENGTH; // not yet initialized
}
if( *path == '/' ) {
@@ -1049,7 +1023,7 @@ int FS_LoadFileEx( const char *path, void **buffer, int flags ) {
if( !FS_ValidatePath( path ) ) {
FS_DPrintf( "FS_LoadFile: refusing invalid path: %s\n", path );
- return -1;
+ return INVALID_LENGTH;
}
// allocate new file handle
@@ -1059,14 +1033,14 @@ int FS_LoadFileEx( const char *path, void **buffer, int flags ) {
// look for it in the filesystem or pack files
length = FS_FOpenFileRead( file, path, qfalse );
- if( length == -1 ) {
- return -1;
+ if( length == INVALID_LENGTH ) {
+ return length;
}
if( buffer ) {
#if USE_ZLIB
if( file->type == FS_GZIP ) {
- length = -1; // unknown length
+ length = INVALID_LENGTH; // unknown length
} else
#endif
{
@@ -1081,11 +1055,11 @@ int FS_LoadFileEx( const char *path, void **buffer, int flags ) {
return length;
}
-int FS_LoadFile( const char *path, void **buffer ) {
+size_t FS_LoadFile( const char *path, void **buffer ) {
return FS_LoadFileEx( path, buffer, 0 );
}
-void *FS_AllocTempMem( int length ) {
+void *FS_AllocTempMem( size_t length ) {
byte *buf;
if( loadInuse + length <= MAX_LOAD_BUFFER && !( fs_restrict_mask->integer & 16 ) ) {
@@ -1138,8 +1112,7 @@ FS_CopyFile
qboolean FS_CopyFile( const char *src, const char *dst ) {
fileHandle_t hSrc, hDst;
byte buffer[MAX_READ];
- int len;
- int size;
+ size_t len, size;
FS_DPrintf( "FS_CopyFile( '%s', '%s' )\n", src, dst );
@@ -1246,7 +1219,7 @@ FS_FPrintf
void FS_FPrintf( fileHandle_t f, const char *format, ... ) {
va_list argptr;
char string[MAXPRINTMSG];
- int len;
+ size_t len;
va_start( argptr, format );
len = Q_vsnprintf( string, sizeof( string ), format, argptr );
@@ -1272,13 +1245,13 @@ static pack_t *FS_LoadPakFile( const char *packfile ) {
dpackfile_t *dfile;
int numpackfiles;
char *names;
- int namesLength;
+ size_t namesLength;
pack_t *pack;
FILE *packhandle;
dpackfile_t info[MAX_FILES_IN_PACK];
int hashSize;
unsigned hash;
- int len;
+ size_t len;
packhandle = fopen( packfile, "rb" );
if( !packhandle ) {
@@ -1354,9 +1327,9 @@ static pack_t *FS_LoadPakFile( const char *packfile ) {
// parse the directory
for( i = 0, file = pack->files, dfile = info; i < pack->numfiles; i++, file++, dfile++ ) {
len = strlen( dfile->name ) + 1;
- file->name = names;
- strcpy( file->name, dfile->name );
+ file->name = memcpy( names, dfile->name, len );
+ names += len;
file->filepos = LittleLong( dfile->filepos );
file->filelen = LittleLong( dfile->filelen );
@@ -1364,8 +1337,6 @@ static pack_t *FS_LoadPakFile( const char *packfile ) {
hash = Com_HashPath( file->name, hashSize );
file->hashNext = pack->fileHash[hash];
pack->fileHash[hash] = file;
-
- names += len;
}
FS_DPrintf( "%s: %d files, %d hash table entries\n",
@@ -1394,10 +1365,10 @@ static pack_t *FS_LoadZipFile( const char *packfile ) {
unz_global_info zGlobalInfo;
unz_file_info zInfo;
char name[MAX_QPATH];
- int namesLength;
+ size_t namesLength;
int hashSize;
unsigned hash;
- int len;
+ size_t len;
zFile = unzOpen( packfile );
if( !zFile ) {
@@ -1560,10 +1531,10 @@ then loads and adds pak*.pak, then anything else in alphabethical order.
static void q_printf( 1, 2 ) FS_AddGameDirectory( const char *fmt, ... ) {
va_list argptr;
searchpath_t *search;
- int length;
+ size_t len;
va_start( argptr, fmt );
- length = Q_vsnprintf( fs_gamedir, sizeof( fs_gamedir ), fmt, argptr );
+ len = Q_vsnprintf( fs_gamedir, sizeof( fs_gamedir ), fmt, argptr );
va_end( argptr );
#ifdef _WIN32
@@ -1574,9 +1545,9 @@ static void q_printf( 1, 2 ) FS_AddGameDirectory( const char *fmt, ... ) {
// add the directory to the search path
//
if( !( fs_restrict_mask->integer & 1 ) ) {
- search = FS_Malloc( sizeof( searchpath_t ) + length );
+ search = FS_Malloc( sizeof( searchpath_t ) + len );
search->pack = NULL;
- memcpy( search->filename, fs_gamedir, length + 1 );
+ memcpy( search->filename, fs_gamedir, len + 1 );
search->next = fs_searchpaths;
fs_searchpaths = search;
}
@@ -1603,9 +1574,9 @@ static void q_printf( 1, 2 ) FS_AddGameDirectory( const char *fmt, ... ) {
FS_CopyInfo
=================
*/
-fsFileInfo_t *FS_CopyInfo( const char *name, int size, time_t ctime, time_t mtime ) {
+fsFileInfo_t *FS_CopyInfo( const char *name, size_t size, time_t ctime, time_t mtime ) {
fsFileInfo_t *out;
- int len;
+ size_t len;
if( !name ) {
return NULL;
@@ -1765,7 +1736,8 @@ void **FS_ListFiles( const char *path,
void **dirlist;
int dircount;
void **list;
- int i, len, pathlen;
+ int i;
+ size_t len, pathlen;
char *s;
if( flags & FS_SEARCH_BYFILTER ) {
@@ -2119,7 +2091,7 @@ static void FS_WhereIs_f( void ) {
entry = pak->fileHash[ hash & ( pak->hashSize - 1 ) ];
for( ; entry; entry = entry->hashNext ) {
if( !Q_stricmp( entry->name, path ) ) {
- Com_Printf( "%s/%s (%d bytes)\n", pak->filename,
+ Com_Printf( "%s/%s (%"PRIz" bytes)\n", pak->filename,
path, entry->filelen );
if( Cmd_Argc() < 3 ) {
return;
@@ -2132,7 +2104,7 @@ static void FS_WhereIs_f( void ) {
search->filename, "/", path, NULL );
//FS_ConvertToSysPath( fullpath );
if( Sys_GetPathInfo( fullpath, &info ) ) {
- Com_Printf( "%s/%s (%d bytes)\n", search->filename, filename, info.size );
+ Com_Printf( "%s/%s (%"PRIz" bytes)\n", search->filename, filename, info.size );
if( Cmd_Argc() < 3 ) {
return;
}
@@ -2319,7 +2291,8 @@ static void FS_UnLink_f( void ) {
}
static void FS_Link_f( void ) {
- int argc, length, count;
+ int argc, count;
+ size_t length;
fsLink_t *l;
char *name, *target;
@@ -2352,7 +2325,7 @@ static void FS_Link_f( void ) {
length = strlen( name );
l = FS_Malloc( sizeof( *l ) + length );
strcpy( l->name, name );
- l->nameLength = length;
+ l->namelen = length;
l->next = fs_links;
fs_links = l;
} else {
@@ -2361,7 +2334,7 @@ static void FS_Link_f( void ) {
target = Cmd_Argv( 2 );
l->target = FS_CopyString( target );
- l->targetLength = strlen( target );
+ l->targlen = strlen( target );
}
static void FS_FreeSearchPath( searchpath_t *path ) {
diff --git a/source/gl_draw.c b/source/gl_draw.c
index 6ea5f42..9387a9e 100644
--- a/source/gl_draw.c
+++ b/source/gl_draw.c
@@ -270,7 +270,7 @@ void Draw_Char( int x, int y, int flags, int ch, qhandle_t hFont ) {
draw.color, R_ImageForHandle( hFont ) );
}
-int Draw_String( int x, int y, int flags, int maxChars,
+int Draw_String( int x, int y, int flags, size_t maxChars,
const char *string, qhandle_t hFont )
{
byte c;
diff --git a/source/gl_images.c b/source/gl_images.c
index 44e47a2..42debe7 100644
--- a/source/gl_images.c
+++ b/source/gl_images.c
@@ -756,7 +756,7 @@ void R_LoadImage( image_t *image, byte *pic, int width, int height,
// HACK: get dimensions from 8-bit texture
if( flags & (if_replace_wal|if_replace_pcx) ) {
char buffer[MAX_QPATH];
- int length;
+ size_t length;
miptex_t mt;
pcx_t pcx;
fileHandle_t f;
@@ -879,8 +879,7 @@ R_LoadWal
*/
image_t *R_LoadWal( const char *name ) {
miptex_t *mt;
- uint32_t width, height, offset;
- unsigned length, endpos;
+ size_t width, height, offset, length, endpos;
image_t *image;
length = fs.LoadFile( name, ( void ** )&mt );
@@ -892,12 +891,12 @@ image_t *R_LoadWal( const char *name ) {
height = LittleLong( mt->height );
offset = LittleLong( mt->offsets[0] );
- if( width < 1 || width > MAX_TEXTURE_SIZE || height < 1 || height > MAX_TEXTURE_SIZE ) {
+ if( width < 1 || height < 1 || width > MAX_TEXTURE_SIZE || height > MAX_TEXTURE_SIZE ) {
Com_WPrintf( "LoadWAL: %s: bad dimensions\n", name );
goto fail;
}
endpos = offset + width * height;
- if( offset > endpos || endpos > length ) {
+ if( endpos < offset || endpos > length ) {
Com_WPrintf( "LoadWAL: %s: bad offset\n", name );
goto fail;
}
diff --git a/source/gl_local.h b/source/gl_local.h
index 6061ffb..5d91611 100644
--- a/source/gl_local.h
+++ b/source/gl_local.h
@@ -290,7 +290,7 @@ void Draw_Fill( int x, int y, int w, int h, int c );
void Draw_FillEx( int x, int y, int w, int h, const color_t color );
void Draw_FadeScreen( void );
void Draw_Char( int x, int y, int flags, int ch, qhandle_t hFont );
-int Draw_String( int x, int y, int flags, int maxChars,
+int Draw_String( int x, int y, int flags, size_t maxChars,
const char *string, qhandle_t hFont );
void Draw_Stringf( int x, int y, const char *fmt, ... );
void Draw_Stats( void );
diff --git a/source/gl_main.c b/source/gl_main.c
index f53d2ee..76e78fd 100644
--- a/source/gl_main.c
+++ b/source/gl_main.c
@@ -539,7 +539,7 @@ static char *screenshot_path( char *buffer, const char *ext ) {
//
for( i = 0; i < 1000; i++ ) {
Com_sprintf( buffer, MAX_OSPATH, SCREENSHOTS_DIRECTORY"/quake%03d%s", i, ext );
- if( fs.LoadFileEx( buffer, NULL, FS_PATH_GAME ) == -1 ) {
+ if( fs.LoadFileEx( buffer, NULL, FS_PATH_GAME ) == INVALID_LENGTH ) {
return buffer; // file doesn't exist
}
}
diff --git a/source/gl_models.c b/source/gl_models.c
index a586e25..5defe24 100644
--- a/source/gl_models.c
+++ b/source/gl_models.c
@@ -848,7 +848,8 @@ void GL_GetModelSize( qhandle_t hModel, vec3_t mins, vec3_t maxs ) {
}
qhandle_t GL_RegisterModel( const char *name ) {
- int index, length, nameLength;
+ int index, length = 0;
+ size_t namelen;
model_t *model;
byte *rawdata;
uint32_t ident;
@@ -869,9 +870,9 @@ qhandle_t GL_RegisterModel( const char *name ) {
return 0;
}
- nameLength = strlen( name );
- if( nameLength > MAX_QPATH - 1 ) {
- Com_Error( ERR_DROP, "%s: oversize name: %d chars", __func__, nameLength );
+ namelen = strlen( name );
+ if( namelen > MAX_QPATH - 1 ) {
+ Com_Error( ERR_DROP, "%s: oversize name", __func__ );
}
model = Model_Find( name );
@@ -879,18 +880,18 @@ qhandle_t GL_RegisterModel( const char *name ) {
goto finish;
}
- length = -1;
+ rawdata = NULL;
buffer[0] = 0;
if( gl_override_models->integer ) {
- if( nameLength > 4 && !strcmp( name + nameLength - 4, ".md2" ) ) {
+ if( namelen > 4 && !strcmp( name + namelen - 4, ".md2" ) ) {
strcpy( buffer, name );
- buffer[nameLength - 1] = '3';
+ buffer[namelen - 1] = '3';
length = fs.LoadFile( buffer, ( void ** )&rawdata );
}
}
- if( length == -1 ) {
+ if( !rawdata ) {
length = fs.LoadFile( name, ( void ** )&rawdata );
- if( length == -1 ) {
+ if( !rawdata ) {
Com_DPrintf( "Couldn't load %s\n", name );
return 0;
}
diff --git a/source/mdfour.c b/source/mdfour.c
index 299edd7..320351b 100644
--- a/source/mdfour.c
+++ b/source/mdfour.c
@@ -135,7 +135,7 @@ void mdfour_begin(struct mdfour *md)
}
-static void mdfour_tail(uint8_t *in, int n)
+static void mdfour_tail(uint8_t *in, size_t n)
{
uint8_t buf[128];
uint32_t M[16];
@@ -162,7 +162,7 @@ static void mdfour_tail(uint8_t *in, int n)
}
}
-void mdfour_update(struct mdfour *md, uint8_t *in, int n)
+void mdfour_update(struct mdfour *md, uint8_t *in, size_t n)
{
uint32_t M[16];
@@ -194,13 +194,13 @@ void mdfour_result(struct mdfour *md, uint8_t *out)
//===================================================================
-uint32_t Com_BlockChecksum( void *buffer, int length ) {
+uint32_t Com_BlockChecksum( void *buffer, size_t len ) {
uint32_t digest[4];
uint32_t val;
struct mdfour md;
mdfour_begin( &md );
- mdfour_update( &md, ( uint8_t * )buffer, length );
+ mdfour_update( &md, ( uint8_t * )buffer, len );
mdfour_result( &md, ( uint8_t * )digest );
val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3];
diff --git a/source/mdfour.h b/source/mdfour.h
index 0d5da8b..f719b53 100644
--- a/source/mdfour.h
+++ b/source/mdfour.h
@@ -31,6 +31,6 @@ typedef struct mdfour {
} mdfour_t;
void mdfour_begin( struct mdfour *md );
-void mdfour_update( struct mdfour *md, uint8_t *in, int n );
+void mdfour_update( struct mdfour *md, uint8_t *in, size_t n );
void mdfour_result( struct mdfour *md, uint8_t *out );
diff --git a/source/mvd_client.c b/source/mvd_client.c
index edcb826..5f4c71f 100644
--- a/source/mvd_client.c
+++ b/source/mvd_client.c
@@ -160,13 +160,13 @@ void MVD_DPrintf( const char *fmt, ... ) {
static void MVD_HttpPrintf( mvd_t *mvd, const char *fmt, ... ) {
char buffer[MAX_STRING_CHARS];
va_list argptr;
- int length;
+ size_t len;
va_start( argptr, fmt );
- length = Q_vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
+ len = Q_vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
va_end( argptr );
- if( FIFO_Write( &mvd->stream.send, buffer, length ) != length ) {
+ if( FIFO_Write( &mvd->stream.send, buffer, len ) != len ) {
MVD_Dropf( mvd, "%s: overflow", __func__ );
}
}
@@ -226,7 +226,7 @@ static void MVD_EmitGamestate( mvd_t *mvd ) {
int i, j;
entity_state_t *es;
player_state_t *ps;
- int length;
+ size_t length;
uint16_t *patch;
int flags, extra, portalbytes;
byte portalbits[MAX_MAP_AREAS/8];
@@ -530,7 +530,7 @@ void MVD_Finish( mvd_t *mvd, const char *reason ) {
static void MVD_ReadDemo( mvd_t *mvd ) {
byte *data;
- int length, read, total = 0;
+ size_t length, read, total = 0;
do {
data = FIFO_Reserve( &mvd->stream.recv, &length );
@@ -568,7 +568,7 @@ static qboolean MVD_ParseResponse( mvd_t *mvd ) {
char *p, *token;
const char *line;
byte *b, *data;
- int length;
+ size_t length;
while( 1 ) {
data = FIFO_Peek( &mvd->stream.recv, &length );
@@ -649,8 +649,8 @@ static qboolean MVD_ParseResponse( mvd_t *mvd ) {
}
static inline float MVD_BufferPercent( mvd_t *mvd ) {
- int usage = FIFO_Usage( &mvd->stream.recv );
- int size = mvd->stream.recv.size;
+ size_t usage = FIFO_Usage( &mvd->stream.recv );
+ size_t size = mvd->stream.recv.size;
#ifdef USE_ZLIB
usage += FIFO_Usage( &mvd->zbuf );
@@ -1254,7 +1254,8 @@ static void MVD_Play_c( genctx_t *ctx, int argnum ) {
void MVD_Play_f( void ) {
char *name = NULL, *s;
char buffer[MAX_OSPATH];
- int loop = 1, len;
+ int loop = 1;
+ size_t len;
mvd_t *mvd;
int c, argc;
string_entry_t *entry, *head;
@@ -1299,11 +1300,11 @@ void MVD_Play_f( void ) {
Q_strncpyz( buffer, s + 1, sizeof( buffer ) );
} else {
Q_concat( buffer, sizeof( buffer ), "demos/", s, NULL );
- if( FS_LoadFile( buffer, NULL ) == -1 ) {
+ if( FS_LoadFile( buffer, NULL ) == INVALID_LENGTH ) {
COM_AppendExtension( buffer, ".mvd2", sizeof( buffer ) );
}
}
- if( FS_LoadFile( buffer, NULL ) == -1 ) {
+ if( FS_LoadFile( buffer, NULL ) == INVALID_LENGTH ) {
Com_Printf( "Ignoring non-existent entry: %s\n", buffer );
continue;
}
diff --git a/source/mvd_game.c b/source/mvd_game.c
index 8b687c1..33b871b 100644
--- a/source/mvd_game.c
+++ b/source/mvd_game.c
@@ -53,7 +53,7 @@ static void MVD_LayoutClients( udpClient_t *client ) {
char layout[MAX_STRING_CHARS];
char buffer[MAX_STRING_CHARS];
char status[MAX_QPATH];
- int length, total;
+ size_t length, total;
udpClient_t *cl;
mvd_t *mvd = client->mvd;
int y, i, prestep;
@@ -121,7 +121,8 @@ static void MVD_LayoutChannels( udpClient_t *client ) {
char layout[MAX_STRING_CHARS];
char buffer[MAX_STRING_CHARS];
mvd_t *mvd;
- int length, total, cursor, y;
+ size_t length, total;
+ int cursor, y;
memcpy( layout, header, sizeof( header ) - 1 );
total = sizeof( header ) - 1;
@@ -189,7 +190,7 @@ static void MVD_LayoutMenu( udpClient_t *client ) {
"xv 240 yv 172 string2 " VERSION;
char layout[MAX_STRING_CHARS];
char cur[MENU_ITEMS];
- int total;
+ size_t total;
if( client->layout_cursor < 0 ) {
client->layout_cursor = MENU_ITEMS - 1;
@@ -535,7 +536,7 @@ SPECTATOR COMMANDS
void MVD_BroadcastPrintf( mvd_t *mvd, int level, int mask, const char *fmt, ... ) {
va_list argptr;
char text[MAXPRINTMSG];
- int len;
+ size_t len;
udpClient_t *other;
client_t *cl;
diff --git a/source/mvd_local.h b/source/mvd_local.h
index 8450f7d..2f2378c 100644
--- a/source/mvd_local.h
+++ b/source/mvd_local.h
@@ -74,24 +74,22 @@ typedef struct {
int clientNum;
/* =================== */
- list_t entry;
- struct mvd_s *mvd;
- client_t *cl;
-
- qboolean admin;
- unsigned begin_time;
- int lastframe;
+ list_t entry;
+ struct mvd_s *mvd;
+ client_t *cl;
+ qboolean admin;
+ unsigned begin_time;
mvd_player_t *target, *oldtarget;
- float fov;
- int uf;
+ float fov;
+ int uf;
mvd_layout_t layout_type;
- int layout_time;
+ unsigned layout_time;
int layout_cursor;
- int floodSamples[FLOOD_SAMPLES];
- int floodHead;
- int floodTime;
+ unsigned floodSamples[FLOOD_SAMPLES];
+ unsigned floodHead;
+ unsigned floodTime;
usercmd_t lastcmd;
//short delta_angles[3];
@@ -108,7 +106,7 @@ typedef struct mvd_s {
// demo related variables
fileHandle_t demoplayback;
fileHandle_t demorecording;
- int demoloop;
+ int demoloop;
string_entry_t *demohead, *demoentry;
// connection variables
@@ -118,18 +116,18 @@ typedef struct mvd_s {
netstream_t stream;
char address[MAX_QPATH];
char response[MAX_NET_STRING];
- int responseLength;
- int contentLength;
+ size_t responseLength;
+ size_t contentLength;
htcoding_t contentCoding;
int statusCode;
char statusText[MAX_QPATH];
- int msglen;
+ size_t msglen;
#if USE_ZLIB
z_stream z;
#endif
fifo_t zbuf;
- int framenum;
- int lastReceived;
+ unsigned framenum;
+ unsigned lastReceived;
unsigned waitTime, waitDelay;
// game state
diff --git a/source/mvd_parse.c b/source/mvd_parse.c
index 946f54e..9fd69fd 100644
--- a/source/mvd_parse.c
+++ b/source/mvd_parse.c
@@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mvd_local.h"
#define MVD_ShowSVC( cmd ) do { \
- Com_Printf( "%3i:%s\n", msg_read.readcount - 1, \
+ Com_Printf( "%3"PRIz":%s\n", msg_read.readcount - 1, \
MVD_ServerCommandString( cmd ) ); \
} while( 0 )
@@ -288,7 +288,7 @@ static void MVD_ParseMulticast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
}
}
-static void MVD_UnicastSend( mvd_t *mvd, qboolean reliable, byte *data, int length, mvd_player_t *player ) {
+static void MVD_UnicastSend( mvd_t *mvd, qboolean reliable, byte *data, size_t length, mvd_player_t *player ) {
mvd_player_t *target;
udpClient_t *client;
client_t *cl;
@@ -333,7 +333,7 @@ static void MVD_UnicastString( mvd_t *mvd, qboolean reliable, mvd_player_t *play
char *string;
mvd_cs_t *cs;
byte *data;
- int readcount, length;
+ size_t readcount, length;
data = msg_read.data + msg_read.readcount - 1;
readcount = msg_read.readcount - 1;
@@ -375,7 +375,7 @@ static void MVD_UnicastPrint( mvd_t *mvd, qboolean reliable, mvd_player_t *playe
int level;
char *string;
byte *data;
- int readcount, length;
+ size_t readcount, length;
udpClient_t *client;
client_t *cl;
mvd_player_t *target;
@@ -410,7 +410,7 @@ static void MVD_UnicastPrint( mvd_t *mvd, qboolean reliable, mvd_player_t *playe
static void MVD_UnicastStuff( mvd_t *mvd, qboolean reliable, mvd_player_t *player ) {
char *string;
byte *data;
- int readcount, length;
+ size_t readcount, length;
data = msg_read.data + msg_read.readcount - 1;
readcount = msg_read.readcount - 1;
@@ -431,7 +431,8 @@ Attempt to parse the datagram and find custom configstrings,
layouts, etc. Give up as soon as unknown command byte is encountered.
*/
static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
- int clientNum, length, last;
+ int clientNum;
+ size_t length, last;
mvd_player_t *player;
byte *data;
qboolean reliable;
@@ -474,7 +475,7 @@ static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
break;
default:
if( mvd_shownet->integer > 1 ) {
- Com_Printf( "%d:SKIPPING UNICAST\n", msg_read.readcount - 1 );
+ Com_Printf( "%"PRIz":SKIPPING UNICAST\n", msg_read.readcount - 1 );
}
// send remaining data and return
data = msg_read.data + msg_read.readcount - 1;
@@ -486,7 +487,7 @@ static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) {
}
if( mvd_shownet->integer > 1 ) {
- Com_Printf( "%d:END OF UNICAST\n", msg_read.readcount - 1 );
+ Com_Printf( "%"PRIz":END OF UNICAST\n", msg_read.readcount - 1 );
}
if( msg_read.readcount > last ) {
@@ -618,7 +619,8 @@ static void MVD_ParseSound( mvd_t *mvd, int extrabits ) {
}
static void MVD_ParseConfigstring( mvd_t *mvd ) {
- int index, length;
+ int index;
+ size_t len;
char *string, *p;
udpClient_t *client;
mvd_player_t *player;
@@ -631,9 +633,9 @@ static void MVD_ParseConfigstring( mvd_t *mvd ) {
MVD_Destroyf( mvd, "%s: bad index: %d", __func__, index );
}
- string = MSG_ReadStringLength( &length );
+ string = MSG_ReadStringLength( &len );
- if( MAX_QPATH * index + length >= sizeof( mvd->configstrings ) ) {
+ if( MAX_QPATH * index + len >= sizeof( mvd->configstrings ) ) {
MVD_Destroyf( mvd, "%s: oversize configstring: %d", __func__, index );
}
@@ -674,11 +676,11 @@ static void MVD_ParseConfigstring( mvd_t *mvd ) {
}
}
- memcpy( mvd->configstrings[index], string, length + 1 );
+ memcpy( mvd->configstrings[index], string, len + 1 );
MSG_WriteByte( svc_configstring );
MSG_WriteShort( index );
- MSG_WriteData( string, length + 1 );
+ MSG_WriteData( string, len + 1 );
// broadcast configstring change
LIST_FOR_EACH( udpClient_t, client, &mvd->udpClients, entry ) {
@@ -867,19 +869,19 @@ static void MVD_ParseFrame( mvd_t *mvd ) {
}
if( mvd_shownet->integer > 1 ) {
- Com_Printf( "%3i:playerinfo\n", msg_read.readcount - 1 );
+ Com_Printf( "%3"PRIz":playerinfo\n", msg_read.readcount - 1 );
}
MVD_ParsePacketPlayers( mvd );
if( mvd_shownet->integer > 1 ) {
- Com_Printf( "%3i:packetentities\n", msg_read.readcount - 1 );
+ Com_Printf( "%3"PRIz":packetentities\n", msg_read.readcount - 1 );
}
MVD_ParsePacketEntities( mvd );
if( mvd_shownet->integer > 1 ) {
- Com_Printf( "%3i: frame:%i\n", msg_read.readcount - 1, mvd->framenum );
+ Com_Printf( "%3"PRIz":frame:%u\n", msg_read.readcount - 1, mvd->framenum );
}
MVD_PlayerToEntityStates( mvd );
@@ -889,11 +891,11 @@ static void MVD_ParseFrame( mvd_t *mvd ) {
static void MVD_ParseServerData( mvd_t *mvd ) {
int protocol;
- int length, index;
+ size_t length;
char *gamedir, *string, *p;
const char *error;
uint32_t checksum;
- int i;
+ int i, index;
mvd_player_t *player;
// clear the leftover from previous level
@@ -1024,8 +1026,8 @@ static void MVD_ParseServerData( mvd_t *mvd ) {
static qboolean MVD_ParseMessage( mvd_t *mvd, fifo_t *fifo ) {
uint16_t msglen;
uint32_t magic;
- byte *data;
- int length;
+ void *data;
+ size_t length;
int cmd, extrabits;
// parse magic
@@ -1040,8 +1042,7 @@ static qboolean MVD_ParseMessage( mvd_t *mvd, fifo_t *fifo ) {
}
// parse msglen
- msglen = mvd->msglen;
- if( !msglen ) {
+ if( !mvd->msglen ) {
if( !FIFO_TryRead( fifo, &msglen, 2 ) ) {
return qfalse;
}
@@ -1050,29 +1051,28 @@ static qboolean MVD_ParseMessage( mvd_t *mvd, fifo_t *fifo ) {
}
msglen = LittleShort( msglen );
if( msglen > MAX_MSGLEN ) {
- MVD_Destroyf( mvd, "Invalid MVD message length: %d bytes", msglen );
+ MVD_Destroyf( mvd, "Invalid MVD message length: %u bytes", msglen );
}
mvd->msglen = msglen;
}
// first, try to read in a single block
data = FIFO_Peek( fifo, &length );
- if( length < msglen ) {
- if( !FIFO_TryRead( fifo, msg_read_buffer, msglen ) ) {
+ if( length < mvd->msglen ) {
+ if( !FIFO_TryRead( fifo, msg_read_buffer, mvd->msglen ) ) {
return qfalse; // not yet available
}
SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
} else {
- SZ_Init( &msg_read, data, msglen );
- FIFO_Decommit( fifo, msglen );
+ SZ_Init( &msg_read, data, mvd->msglen );
+ FIFO_Decommit( fifo, mvd->msglen );
}
+ msg_read.cursize = mvd->msglen;
mvd->msglen = 0;
- msg_read.cursize = msglen;
-
if( mvd_shownet->integer == 1 ) {
- Com_Printf( "%i ", msg_read.cursize );
+ Com_Printf( "%"PRIz" ", msg_read.cursize );
} else if( mvd_shownet->integer > 1 ) {
Com_Printf( "------------------\n" );
}
@@ -1087,7 +1087,7 @@ static qboolean MVD_ParseMessage( mvd_t *mvd, fifo_t *fifo ) {
if( ( cmd = MSG_ReadByte() ) == -1 ) {
if( mvd_shownet->integer > 1 ) {
- Com_Printf( "%3i:END OF MESSAGE\n", msg_read.readcount - 1 );
+ Com_Printf( "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1 );
}
break;
}
@@ -1132,7 +1132,7 @@ static qboolean MVD_ParseMessage( mvd_t *mvd, fifo_t *fifo ) {
MVD_ParsePrint( mvd );
break;
default:
- MVD_Destroyf( mvd, "Illegible command at %d: %d",
+ MVD_Destroyf( mvd, "Illegible command at %"PRIz": %d",
msg_read.readcount - 1, cmd );
}
}
@@ -1143,7 +1143,7 @@ static qboolean MVD_ParseMessage( mvd_t *mvd, fifo_t *fifo ) {
#if USE_ZLIB
static int MVD_Decompress( mvd_t *mvd ) {
byte *data;
- int avail_in, avail_out;
+ size_t avail_in, avail_out;
z_streamp z = &mvd->z;
int ret = Z_BUF_ERROR;
@@ -1153,14 +1153,14 @@ static int MVD_Decompress( mvd_t *mvd ) {
break;
}
z->next_in = data;
- z->avail_in = avail_in;
+ z->avail_in = ( uInt )avail_in;
data = FIFO_Reserve( &mvd->zbuf, &avail_out );
if( !avail_out ) {
break;
}
z->next_out = data;
- z->avail_out = avail_out;
+ z->avail_out = ( uInt )avail_out;
ret = inflate( z, Z_SYNC_FLUSH );
diff --git a/source/net_chan.c b/source/net_chan.c
index c02678e..c1be960 100644
--- a/source/net_chan.c
+++ b/source/net_chan.c
@@ -115,22 +115,22 @@ neterr_t Netchan_OutOfBandPrint( netsrc_t sock, const netadr_t *address,
{
va_list argptr;
char buffer[MAX_PACKETLEN_DEFAULT];
- int length;
+ size_t len;
// write the packet header
*( uint32_t * )buffer = 0xffffffff;
va_start( argptr, format );
- length = Q_vsnprintf( buffer + 4, sizeof( buffer ) - 4, format, argptr );
+ len = Q_vsnprintf( buffer + 4, sizeof( buffer ) - 4, format, argptr );
va_end( argptr );
// send the datagram
- return NET_SendPacket( sock, address, length + 4, buffer );
+ return NET_SendPacket( sock, address, len + 4, buffer );
}
// ============================================================================
-static int NetchanOld_TransmitNextFragment( netchan_t *netchan ) {
+static size_t NetchanOld_TransmitNextFragment( netchan_t *netchan ) {
Com_Error( ERR_FATAL, "NetchanOld_TransmitNextFragment: not implemented" );
return 0;
}
@@ -145,7 +145,7 @@ transmition / retransmition of the reliable messages.
A 0 length will still generate a packet and deal with the reliable messages.
================
*/
-static int NetchanOld_Transmit( netchan_t *netchan, int length, const byte *data ) {
+static size_t NetchanOld_Transmit( netchan_t *netchan, size_t length, const void *data ) {
netchan_old_t *chan = ( netchan_old_t * )netchan;
sizebuf_t send;
byte send_buf[MAX_PACKETLEN];
@@ -158,7 +158,7 @@ static int NetchanOld_Transmit( netchan_t *netchan, int length, const byte *data
netchan->fatal_error = qtrue;
Com_WPrintf( "%s: outgoing message overflow\n",
NET_AdrToString( &netchan->remote_address ) );
- return -1;
+ return 0;
}
send_reliable = qfalse;
@@ -218,7 +218,7 @@ static int NetchanOld_Transmit( netchan_t *netchan, int length, const byte *data
NET_AdrToString( &netchan->remote_address ) );
if( showpackets->integer ) {
- Com_Printf( "send %4i : s=%i ack=%i rack=%i",
+ Com_Printf( "send %4"PRIz" : s=%d ack=%d rack=%d",
send.cursize,
netchan->outgoing_sequence - 1,
netchan->incoming_sequence,
@@ -233,11 +233,10 @@ static int NetchanOld_Transmit( netchan_t *netchan, int length, const byte *data
ret = NET_SendPacket( netchan->sock, &netchan->remote_address,
send.cursize, send.data );
if( ret == NET_ERROR ) {
- return -1;
+ return 0;
}
return send.cursize;
-
}
/*
@@ -274,13 +273,13 @@ static qboolean NetchanOld_Process( netchan_t *netchan ) {
sequence_ack &= ~( 1 << 31 );
if( showpackets->integer ) {
- Com_Printf( "recv %4i : s=%i ack=%i rack=%i",
+ Com_Printf( "recv %4"PRIz" : s=%d ack=%d rack=%d",
msg_read.cursize,
sequence,
sequence_ack,
reliable_ack );
if( reliable_message ) {
- Com_Printf( " reliable=%i", chan->incoming_reliable_sequence ^ 1 );
+ Com_Printf( " reliable=%d", chan->incoming_reliable_sequence ^ 1 );
}
Com_Printf( "\n" );
}
@@ -358,7 +357,7 @@ called to open a channel to a remote system
==============
*/
static netchan_t *NetchanOld_Setup( netsrc_t sock, const netadr_t *adr,
- int qport, int maxpacketlen )
+ int qport, size_t maxpacketlen )
{
netchan_old_t *chan;
netchan_t *netchan;
@@ -397,14 +396,14 @@ static netchan_t *NetchanOld_Setup( netsrc_t sock, const netadr_t *adr,
NetchanNew_TransmitNextFragment
================
*/
-static int NetchanNew_TransmitNextFragment( netchan_t *netchan ) {
+static size_t NetchanNew_TransmitNextFragment( netchan_t *netchan ) {
netchan_new_t *chan = ( netchan_new_t * )netchan;
sizebuf_t send;
byte send_buf[MAX_PACKETLEN];
qboolean send_reliable;
uint32_t w1, w2;
uint16_t offset;
- int fragment_length;
+ size_t fragment_length;
qboolean more_fragments;
neterr_t ret;
@@ -448,8 +447,8 @@ static int NetchanNew_TransmitNextFragment( netchan_t *netchan ) {
fragment_length );
if( showpackets->integer ) {
- Com_Printf( "send %4i : s=%i ack=%i rack=%i "
- "fragment_offset=%i more_fragments=%i",
+ Com_Printf( "send %4"PRIz" : s=%d ack=%d rack=%d "
+ "fragment_offset=%"PRIz" more_fragments=%d",
send.cursize,
netchan->outgoing_sequence,
netchan->incoming_sequence,
@@ -476,7 +475,7 @@ static int NetchanNew_TransmitNextFragment( netchan_t *netchan ) {
ret = NET_SendPacket( netchan->sock, &netchan->remote_address,
send.cursize, send.data );
if( ret == NET_ERROR ) {
- return -1;
+ return 0;
}
return send.cursize;
@@ -487,9 +486,7 @@ static int NetchanNew_TransmitNextFragment( netchan_t *netchan ) {
NetchanNew_Transmit
================
*/
-static int NetchanNew_Transmit( netchan_t *netchan, int length,
- const byte *data )
-{
+static size_t NetchanNew_Transmit( netchan_t *netchan, size_t length, const void *data ) {
netchan_new_t *chan = ( netchan_new_t * )netchan;
sizebuf_t send;
byte send_buf[MAX_PACKETLEN];
@@ -502,7 +499,7 @@ static int NetchanNew_Transmit( netchan_t *netchan, int length,
netchan->fatal_error = qtrue;
Com_WPrintf( "%s: outgoing message overflow\n",
NET_AdrToString( &netchan->remote_address ) );
- return -1;
+ return 0;
}
if( netchan->fragment_pending ) {
@@ -574,13 +571,13 @@ static int NetchanNew_Transmit( netchan_t *netchan, int length,
SZ_Write( &send, data, length );
if( showpackets->integer ) {
- Com_Printf( "send %4i : s=%i ack=%i rack=%i",
+ Com_Printf( "send %4"PRIz" : s=%d ack=%d rack=%d",
send.cursize,
netchan->outgoing_sequence - 1,
netchan->incoming_sequence,
chan->incoming_reliable_sequence );
if( send_reliable ) {
- Com_Printf( " reliable=%i", chan->reliable_sequence );
+ Com_Printf( " reliable=%d", chan->reliable_sequence );
}
Com_Printf( "\n" );
}
@@ -589,7 +586,7 @@ static int NetchanNew_Transmit( netchan_t *netchan, int length,
ret = NET_SendPacket( netchan->sock, &netchan->remote_address,
send.cursize, send.data );
if( ret == NET_ERROR ) {
- return -1;
+ return 0;
}
return send.cursize;
@@ -605,7 +602,7 @@ static qboolean NetchanNew_Process( netchan_t *netchan ) {
uint32_t sequence, sequence_ack, reliable_ack;
qboolean reliable_message, fragmented_message, more_fragments;
uint16_t fragment_offset;
- int length;
+ size_t length;
// get sequence numbers
MSG_BeginReading();
@@ -633,14 +630,14 @@ static qboolean NetchanNew_Process( netchan_t *netchan ) {
}
if( showpackets->integer ) {
- Com_Printf( "recv %4i : s=%i ack=%i rack=%i", msg_read.cursize,
- sequence, sequence_ack, reliable_ack );
+ Com_Printf( "recv %4"PRIz" : s=%d ack=%d rack=%d",
+ msg_read.cursize, sequence, sequence_ack, reliable_ack );
if( fragmented_message ) {
- Com_Printf( " fragment_offset=%i more_fragments=%i",
- fragment_offset, more_fragments );
+ Com_Printf( " fragment_offset=%d more_fragments=%d",
+ fragment_offset, more_fragments );
}
if( reliable_message ) {
- Com_Printf( " reliable=%i", chan->incoming_reliable_sequence ^ 1 );
+ Com_Printf( " reliable=%d", chan->incoming_reliable_sequence ^ 1 );
}
Com_Printf( "\n" );
}
@@ -774,7 +771,7 @@ NetchanNew_Setup
==============
*/
static netchan_t *NetchanNew_Setup( netsrc_t sock, const netadr_t *adr,
- int qport, int maxpacketlen )
+ int qport, size_t maxpacketlen )
{
netchan_new_t *chan;
netchan_t *netchan;
@@ -810,7 +807,7 @@ Netchan_Setup
==============
*/
netchan_t *Netchan_Setup( netsrc_t sock, netchan_type_t type,
- const netadr_t *adr, int qport, int maxpacketlen, int protocol )
+ const netadr_t *adr, int qport, size_t maxpacketlen, int protocol )
{
netchan_t *netchan;
diff --git a/source/net_common.c b/source/net_common.c
index 1474af2..abe45c0 100644
--- a/source/net_common.c
+++ b/source/net_common.c
@@ -54,13 +54,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
typedef struct {
byte data[MAX_PACKETLEN];
- int datalen;
+ size_t datalen;
} loopmsg_t;
typedef struct {
loopmsg_t msgs[MAX_LOOPBACK];
- int get;
- int send;
+ unsigned get;
+ unsigned send;
} loopback_t;
cvar_t *net_ip;
@@ -83,10 +83,10 @@ static netflag_t net_active;
static int net_error;
static unsigned net_statTime;
-static int net_rcvd;
-static int net_sent;
-static int net_rate_dn;
-static int net_rate_up;
+static size_t net_rcvd;
+static size_t net_sent;
+static size_t net_rate_dn;
+static size_t net_rate_up;
//=============================================================================
@@ -286,7 +286,7 @@ NET_LogPacket
=============
*/
static void NET_LogPacket( const netadr_t *address, const char *prefix,
- const byte *data, unsigned length )
+ const byte *data, size_t length )
{
int numRows;
int i, j, c;
@@ -475,12 +475,12 @@ neterr_t NET_GetPacket( netsrc_t sock ) {
NET_SendPacket
=============
*/
-neterr_t NET_SendPacket( netsrc_t sock, const netadr_t *to, unsigned length, const void *data ) {
+neterr_t NET_SendPacket( netsrc_t sock, const netadr_t *to, size_t length, const void *data ) {
struct sockaddr_in addr;
int ret;
- if( length > MAX_PACKETLEN ) {
- Com_WPrintf( "%s: bad length: %u bytes\n", __func__, length );
+ if( length < 1 || length > MAX_PACKETLEN ) {
+ Com_WPrintf( "%s: bad length: %"PRIz" bytes\n", __func__, length );
return NET_ERROR;
}
@@ -892,7 +892,7 @@ neterr_t NET_Run( netstream_t *s ) {
struct timeval tv;
fd_set rfd, wfd, efd;
int ret, err;
- int length;
+ size_t length;
byte *data;
neterr_t result = NET_AGAIN;
@@ -1207,12 +1207,12 @@ qboolean NET_GetAddress( netsrc_t sock, netadr_t *adr ) {
return qtrue;
}
-static int NET_UpRate_m( char *buffer, int size ) {
- return Com_sprintf( buffer, size, "%d", net_rate_up );
+static size_t NET_UpRate_m( char *buffer, size_t size ) {
+ return Com_sprintf( buffer, size, "%"PRIz, net_rate_up );
}
-static int NET_DnRate_m( char *buffer, int size ) {
- return Com_sprintf( buffer, size, "%d", net_rate_dn );
+static size_t NET_DnRate_m( char *buffer, size_t size ) {
+ return Com_sprintf( buffer, size, "%"PRIz, net_rate_dn );
}
/*
diff --git a/source/prompt.c b/source/prompt.c
index d108c62..3536f2f 100644
--- a/source/prompt.c
+++ b/source/prompt.c
@@ -34,8 +34,9 @@ static void Prompt_ShowMatches( commandPrompt_t *prompt, char **matches,
{
int count = end - start;
int numCols = 7, numLines;
- int i, j, k, max, len, total;
- int colwidths[6];
+ int i, j, k;
+ size_t max, len, total;
+ size_t colwidths[6];
char *match;
do {
@@ -47,7 +48,7 @@ static void Prompt_ShowMatches( commandPrompt_t *prompt, char **matches,
if( k >= end ) {
break;
}
- max = -9999;
+ max = 0;
j = k;
while( j - k < numLines && j < end ) {
len = strlen( matches[j++] );
@@ -150,7 +151,8 @@ Prompt_CompleteCommand
void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
inputField_t *inputLine = &prompt->inputLine;
char *text, *partial, *s;
- int i, argc, pos, currentArg, size, length, argnum;
+ int i, argc, currentArg, argnum;
+ size_t size, len, pos;
char *first, *last;
genctx_t ctx;
char *matches[MAX_MATCHES], *sortedMatches[MAX_MATCHES];
@@ -176,8 +178,8 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
argc = Cmd_Argc();
currentArg = Cmd_FindArgForOffset( pos );
- i = strlen( text );
- if( i != 0 && text[ i - 1 ] == ' ' ) {
+ len = strlen( text );
+ if( len > 0 && text[ len - 1 ] == ' ' ) {
if( currentArg == argc - 1 ) {
currentArg++;
}
@@ -263,13 +265,13 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
// copy matching part
first = sortedMatches[0];
last = sortedMatches[ ctx.count - 1 ];
- length = 0;
+ len = 0;
do {
if( *first != *last ) {
break;
}
- text[length++] = *first;
- if( length == size - 1 ) {
+ text[len++] = *first;
+ if( len == size - 1 ) {
break;
}
@@ -277,13 +279,13 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
last++;
} while( *first );
- text[length] = 0;
- pos += length;
- size -= length;
+ text[len] = 0;
+ pos += len;
+ size -= len;
if( currentArg + 1 < argc ) {
s = Cmd_RawArgsFrom( currentArg + 1 );
- pos += Q_concat( text + length, size, " ", s, NULL );
+ pos += Q_concat( text + len, size, " ", s, NULL );
}
inputLine->cursorPos = pos + 1;
@@ -454,7 +456,8 @@ void Prompt_SaveHistory( commandPrompt_t *prompt, const char *filename, int line
void Prompt_LoadHistory( commandPrompt_t *prompt, const char *filename ) {
char buffer[MAX_FIELD_TEXT];
fileHandle_t f;
- int i, len;
+ int i;
+ size_t len;
FS_FOpenFile( filename, &f, FS_MODE_READ|FS_TYPE_REAL );
if( !f ) {
diff --git a/source/q_field.c b/source/q_field.c
index f622217..7400434 100644
--- a/source/q_field.c
+++ b/source/q_field.c
@@ -34,7 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
IF_Init
================
*/
-void IF_Init( inputField_t *field, int visibleChars, int maxChars ) {
+void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars, const char *text ) {
memset( field, 0, sizeof( *field ) );
clamp( maxChars, 1, sizeof( field->text ) );
@@ -42,25 +42,10 @@ void IF_Init( inputField_t *field, int visibleChars, int maxChars ) {
field->maxChars = maxChars;
field->visibleChars = visibleChars;
-}
-/*
-================
-IF_InitText
-================
-*/
-void IF_InitText( inputField_t *field, int visibleChars, int maxChars,
- const char *text )
-{
- memset( field, 0, sizeof( *field ) );
-
- clamp( maxChars, 1, sizeof( field->text ) );
- clamp( visibleChars, 1, maxChars );
-
- field->maxChars = maxChars;
- field->visibleChars = visibleChars;
-
- field->cursorPos = Q_strncpyz( field->text, text, sizeof( field->text ) );
+ if( text ) {
+ field->cursorPos = Q_strncpyz( field->text, text, maxChars );
+ }
}
/*
@@ -111,7 +96,7 @@ qboolean IF_KeyEvent( inputField_t *field, int key ) {
}
if( key == 'w' && keys.IsDown( K_CTRL ) ) {
- int oldpos = field->cursorPos;
+ size_t oldpos = field->cursorPos;
// kill trailing whitespace
while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) {
@@ -241,7 +226,8 @@ Returns x offset of the rightmost character drawn.
*/
int IF_Draw( inputField_t *field, int x, int y, int flags, qhandle_t hFont ) {
char *text;
- int cursorPos, offset, ret;
+ size_t cursorPos, offset;
+ int ret;
int cw, ch;
if( field->cursorPos > sizeof( field->text ) - 1 ) {
diff --git a/source/q_field.h b/source/q_field.h
index e9d932a..eeca72a 100644
--- a/source/q_field.h
+++ b/source/q_field.h
@@ -31,16 +31,14 @@ LINE EDITING
typedef struct inputField_s {
char text[MAX_FIELD_TEXT];
- int maxChars;
- int visibleChars;
- int cursorPos;
+ size_t maxChars;
+ size_t visibleChars;
+ size_t cursorPos;
} inputField_t;
qboolean IF_KeyEvent( inputField_t *field, int key );
qboolean IF_CharEvent( inputField_t *field, int key );
-void IF_Init( inputField_t *field, int visibleChars, int maxChars );
-void IF_InitText( inputField_t *field, int visibleChars, int maxChars,
- const char *text );
+void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars, const char *text );
void IF_Clear( inputField_t *field );
void IF_Replace( inputField_t *field, const char *text );
int IF_Draw( inputField_t *field, int x, int y, int flags,
diff --git a/source/q_msg.c b/source/q_msg.c
index f95cc66..69bb044 100644
--- a/source/q_msg.c
+++ b/source/q_msg.c
@@ -145,7 +145,7 @@ MSG_WriteString
=============
*/
void MSG_WriteString( const char *string ) {
- int length;
+ size_t length;
if( !string ) {
MSG_WriteByte( 0 );
@@ -154,7 +154,7 @@ void MSG_WriteString( const char *string ) {
length = strlen( string );
if( length >= MAX_NET_STRING ) {
- Com_WPrintf( "MSG_WriteString: overflow: %d chars", length );
+ Com_WPrintf( "%s: overflow: %"PRIz" chars", __func__, length );
MSG_WriteByte( 0 );
return;
}
@@ -297,7 +297,8 @@ MSG_WriteBits
=============
*/
void MSG_WriteBits( int value, int bits ) {
- int i, bitpos;
+ int i;
+ size_t bitpos;
if( bits == 0 || bits < -31 || bits > 32 ) {
Com_Error( ERR_FATAL, "MSG_WriteBits: bad bits: %d", bits );
@@ -1402,13 +1403,13 @@ void MSG_FlushTo( sizebuf_t *dest ) {
void MSG_Printf( const char *fmt, ... ) {
char buffer[MAX_STRING_CHARS];
va_list argptr;
- int length;
+ size_t len;
va_start( argptr, fmt );
- length = Q_vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
+ len = Q_vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
va_end( argptr );
- MSG_WriteData( buffer, length );
+ MSG_WriteData( buffer, len );
}
//============================================================
@@ -1501,7 +1502,7 @@ int MSG_ReadLong ( void )
return c;
}
-char *MSG_ReadStringLength( int *length ) {
+char *MSG_ReadStringLength( size_t *length ) {
static char string[2][MAX_NET_STRING];
static int index;
char *s;
@@ -1724,7 +1725,8 @@ void MSG_ReadDeltaUsercmd_Hacked( const usercmd_t *from, usercmd_t *to ) {
}
int MSG_ReadBits( int bits ) {
- int i, get, bitpos;
+ int i, get;
+ size_t bitpos;
qboolean sgn;
int value;
@@ -2712,14 +2714,14 @@ const char *MSG_ServerCommandString( int cmd ) {
//===========================================================================
-void SZ_TagInit( sizebuf_t *buf, void *data, int length, uint32_t tag ) {
+void SZ_TagInit( sizebuf_t *buf, void *data, size_t length, uint32_t tag ) {
memset( buf, 0, sizeof( *buf ) );
buf->data = data;
buf->maxsize = length;
buf->tag = tag;
}
-void SZ_Init( sizebuf_t *buf, void *data, int length ) {
+void SZ_Init( sizebuf_t *buf, void *data, size_t length ) {
memset( buf, 0, sizeof( *buf ) );
buf->data = data;
buf->maxsize = length;
@@ -2733,15 +2735,19 @@ void SZ_Clear( sizebuf_t *buf ) {
buf->overflowed = qfalse;
}
-void *SZ_GetSpace( sizebuf_t *buf, int length ) {
+void *SZ_GetSpace( sizebuf_t *buf, size_t length ) {
void *data;
if( buf->cursize + length > buf->maxsize ) {
if( !buf->allowoverflow ) {
- Com_Error( ERR_FATAL, "SZ_GetSpace: %#x: overflow without allowoverflow set", buf->tag );
+ Com_Error( ERR_FATAL,
+ "%s: %#x: overflow without allowoverflow set",
+ __func__, buf->tag );
}
if( length > buf->maxsize ) {
- Com_Error( ERR_FATAL, "SZ_GetSpace: %#x: %d is > full buffer size", buf->tag, length );
+ Com_Error( ERR_FATAL,
+ "%s: %#x: %"PRIz" is > full buffer size %"PRIz"",
+ __func__, buf->tag, length, buf->maxsize );
}
Com_DPrintf( "SZ_GetSpace: %#x: overflow\n", buf->tag );
@@ -2756,7 +2762,7 @@ void *SZ_GetSpace( sizebuf_t *buf, int length ) {
return data;
}
-void SZ_Write( sizebuf_t *buf, const void *data, int length ) {
+void SZ_Write( sizebuf_t *buf, const void *data, size_t length ) {
memcpy( SZ_GetSpace( buf, length ), data, length );
}
@@ -2792,7 +2798,7 @@ void SZ_WritePos( sizebuf_t *sb, const vec3_t pos ) {
}
void SZ_WriteString( sizebuf_t *sb, const char *string ) {
- int length;
+ size_t length;
int c;
if( !string ) {
@@ -2802,7 +2808,7 @@ void SZ_WriteString( sizebuf_t *sb, const char *string ) {
length = strlen( string );
if( length > MAX_NET_STRING - 1 ) {
- Com_WPrintf( "SZ_WriteString: overflow: %d chars", length );
+ Com_WPrintf( "%s: overflow: %"PRIz" chars", __func__, length );
SZ_WriteByte( sb, 0 );
return;
}
diff --git a/source/q_msg.h b/source/q_msg.h
index 37d319b..e9a9900 100644
--- a/source/q_msg.h
+++ b/source/q_msg.h
@@ -35,17 +35,17 @@ typedef struct sizebuf_s {
qboolean allowoverflow;
qboolean overflowed; // set to qtrue if the buffer size failed
byte *data;
- int maxsize;
- int cursize;
- int readcount;
- int bitpos;
+ size_t maxsize;
+ size_t cursize;
+ size_t readcount;
+ size_t bitpos;
} sizebuf_t;
-void SZ_Init( sizebuf_t *buf, void *data, int length );
-void SZ_TagInit( sizebuf_t *buf, void *data, int length, uint32_t tag );
+void SZ_Init( sizebuf_t *buf, void *data, size_t length );
+void SZ_TagInit( sizebuf_t *buf, void *data, size_t length, uint32_t tag );
void SZ_Clear( sizebuf_t *buf );
-void *SZ_GetSpace( sizebuf_t *buf, int length );
-void SZ_Write( sizebuf_t *buf, const void *data, int length );
+void *SZ_GetSpace( sizebuf_t *buf, size_t length );
+void SZ_Write( sizebuf_t *buf, const void *data, size_t length );
void SZ_WriteByte( sizebuf_t *sb, int c );
void SZ_WriteShort( sizebuf_t *sb, int c );
void SZ_WriteLong( sizebuf_t *sb, int c );
@@ -109,7 +109,7 @@ void MSG_WriteDeltaPlayerstate_Packet( const player_state_t *from, const player_
void MSG_FlushTo( sizebuf_t *dest );
void MSG_Printf( const char *fmt, ... ) q_printf( 1, 2 );
-static inline void MSG_WriteData( const void *data, int length ) {
+static inline void MSG_WriteData( const void *data, size_t length ) {
memcpy( SZ_GetSpace( &msg_write, length ), data, length );
}
@@ -122,7 +122,7 @@ int MSG_ReadLong( void );
float MSG_ReadFloat( void );
char *MSG_ReadString( void );
char *MSG_ReadStringLine( void );
-char *MSG_ReadStringLength( int *length );
+char *MSG_ReadStringLength( size_t *length );
float MSG_ReadCoord( void );
void MSG_ReadPos( vec3_t pos );
float MSG_ReadAngle( void );
@@ -147,7 +147,7 @@ void MSG_ShowDeltaUsercmdBits_Enhanced( int bits );
const char *MSG_ServerCommandString( int cmd );
#define MSG_ShowSVC( cmd ) do { \
- Com_Printf( "%3i:%s\n", msg_read.readcount - 1, \
+ Com_Printf( "%3"PRIz":%s\n", msg_read.readcount - 1, \
MSG_ServerCommandString( cmd ) ); \
} while( 0 )
diff --git a/source/q_shared.c b/source/q_shared.c
index d61bf6d..5368564 100644
--- a/source/q_shared.c
+++ b/source/q_shared.c
@@ -1244,7 +1244,8 @@ char *Q_UnescapeString( const char *string ) {
int Q_EscapeMarkup( char *out, const char *in, int bufsize ) {
char *p, *m, *s;
- int c, l;
+ int c;
+ size_t l;
if( bufsize < 1 ) {
Com_Error( ERR_FATAL, "%s: bad bufsize: %d", __func__, bufsize );
@@ -1735,7 +1736,7 @@ void Com_PageInMemory (void *buffer, int size)
============================================================================
*/
-int Q_strncasecmp( const char *s1, const char *s2, int n ) {
+int Q_strncasecmp( const char *s1, const char *s2, size_t n ) {
int c1, c2;
do {
@@ -1787,8 +1788,8 @@ int Q_strcasecmp( const char *s1, const char *s2 ) {
Q_strncpyz
===============
*/
-int Q_strncpyz( char *dest, const char *src, int destsize ) {
- int len;
+size_t Q_strncpyz( char *dest, const char *src, size_t destsize ) {
+ size_t len;
#ifdef _DEBUG
if( destsize < 1 ) {
@@ -1804,7 +1805,7 @@ int Q_strncpyz( char *dest, const char *src, int destsize ) {
len = strlen( src );
if( len >= destsize ) {
- Com_DPrintf( "%s: overflow of %d in %d\n", __func__, len, destsize - 1 );
+ Com_DPrintf( "%s: overflow of %"PRIz" in %"PRIz"\n", __func__, len, destsize - 1 );
len = destsize - 1;
}
@@ -1819,8 +1820,8 @@ int Q_strncpyz( char *dest, const char *src, int destsize ) {
Q_strcat
===============
*/
-int Q_strcat( char *dest, int destsize, const char *src ) {
- int ofs, len;
+size_t Q_strcat( char *dest, size_t destsize, const char *src ) {
+ size_t ofs, len, total;
#ifdef _DEBUG
if( !dest ) {
@@ -1835,14 +1836,15 @@ int Q_strcat( char *dest, int destsize, const char *src ) {
len = strlen( src );
if( ofs + len >= destsize ) {
- Com_DPrintf( "%s: overflow of %d in %d\n", __func__, ofs + len, destsize - 1 );
+ Com_DPrintf( "%s: overflow of %"PRIz" in %"PRIz"\n", __func__, ofs + len, destsize - 1 );
len = destsize - ofs - 1;
}
- memcpy( dest + ofs, src, len ); ofs += len;
- dest[ofs] = 0;
+ memcpy( dest + ofs, src, len );
+ total = ofs + len;
+ dest[total] = 0;
- return ofs;
+ return total;
}
/*
@@ -1850,24 +1852,24 @@ int Q_strcat( char *dest, int destsize, const char *src ) {
Q_concat
===============
*/
-int Q_concat( char *buffer, int size, ... ) {
+size_t Q_concat( char *dest, size_t destsize, ... ) {
va_list argptr;
const char *s;
- int len, total = 0;
+ size_t len, total = 0;
- va_start( argptr, size );
+ va_start( argptr, destsize );
while( ( s = va_arg( argptr, const char * ) ) != NULL ) {
len = strlen( s );
- if( total + len >= size ) {
- Com_DPrintf( "%s: overflow of %d in %d\n", __func__, total + len, size - 1 );
+ if( total + len >= destsize ) {
+ Com_DPrintf( "%s: overflow of %"PRIz" in %"PRIz"\n", __func__, total + len, destsize - 1 );
break;
}
- memcpy( buffer + total, s, len );
+ memcpy( dest + total, s, len );
total += len;
}
va_end( argptr );
- buffer[total] = 0;
+ dest[total] = 0;
return total;
}
@@ -1891,7 +1893,7 @@ In case of output error, sets dest buffer
to empty string and returns zero.
===============
*/
-int Q_vsnprintf( char *dest, int destsize, const char *fmt, va_list argptr ) {
+size_t Q_vsnprintf( char *dest, size_t destsize, const char *fmt, va_list argptr ) {
int ret;
if( destsize < 1 ) {
@@ -1903,7 +1905,7 @@ int Q_vsnprintf( char *dest, int destsize, const char *fmt, va_list argptr ) {
if( ret >= destsize ) {
// truncated, not terminated
dest[destsize - 1] = 0;
- Com_DPrintf( "%s: overflow of %d in %d\n", __func__, ret, destsize - 1 );
+ Com_DPrintf( "%s: overflow of %d in %"PRIz"\n", __func__, ret, destsize - 1 );
ret = destsize - 1;
} else if( ret == destsize - 1 ) {
// ok, but not terminated
@@ -1912,7 +1914,7 @@ int Q_vsnprintf( char *dest, int destsize, const char *fmt, va_list argptr ) {
ret = vsnprintf( dest, destsize, fmt, argptr );
if( ret >= destsize ) {
// truncated, terminated
- Com_DPrintf( "%s: overflow of %d in %d\n", __func__, ret, destsize - 1 );
+ Com_DPrintf( "%s: overflow of %d in %"PRIz"\n", __func__, ret, destsize - 1 );
ret = destsize - 1;
#endif
} else if( ret < 0 ) {
@@ -1921,7 +1923,7 @@ int Q_vsnprintf( char *dest, int destsize, const char *fmt, va_list argptr ) {
ret = 0;
}
- return ret;
+ return ( size_t )ret;
}
/*
@@ -1929,9 +1931,9 @@ int Q_vsnprintf( char *dest, int destsize, const char *fmt, va_list argptr ) {
Com_sprintf
===============
*/
-int Com_sprintf( char *dest, int destsize, const char *fmt, ... ) {
+size_t Com_sprintf( char *dest, size_t destsize, const char *fmt, ... ) {
va_list argptr;
- int ret;
+ size_t ret;
va_start( argptr, fmt );
ret = Q_vsnprintf( dest, destsize, fmt, argptr );
@@ -2165,7 +2167,7 @@ qboolean Info_SetValueForKey( char *s, const char *key, const char *value ) {
return qtrue;
}
- l = strlen( s );
+ l = ( int )strlen( s );
if( l + kl + vl + 2 >= MAX_INFO_STRING ) {
return qfalse;
}
diff --git a/source/q_shared.h b/source/q_shared.h
index 9933fc2..de1e8f2 100644
--- a/source/q_shared.h
+++ b/source/q_shared.h
@@ -40,7 +40,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#else
#define q_sentinel
#endif
-#define q_packed __attribute__((packed))
#define q_likely( x ) __builtin_expect( !!(x), 1 )
#define q_unlikely( x ) __builtin_expect( !!(x), 0 )
@@ -455,7 +454,7 @@ static inline int Q_charhex( int c ) {
// portable case insensitive compare
int Q_strcasecmp( const char *s1, const char *s2 );
-int Q_strncasecmp( const char *s1, const char *s2, int n );
+int Q_strncasecmp( const char *s1, const char *s2, size_t n );
#define Q_stricmp Q_strcasecmp
#define Q_stricmpn Q_strncasecmp
@@ -487,11 +486,11 @@ unsigned Com_HashString( const char *string, int hashSize );
unsigned Com_HashPath( const char *string, int hashSize );
// buffer safe operations
-int Q_strncpyz( char *dest, const char *src, int destsize );
-int Q_strcat( char *dest, int destsize, const char *src );
-int Q_concat( char *buffer, int size, ... ) q_sentinel;
-int Com_sprintf( char *dest, int destsize, const char *fmt, ... ) q_printf( 3, 4 );
-int Q_vsnprintf( char *dest, int destsize, const char *fmt, va_list argptr );
+size_t Q_strncpyz( char *dest, const char *src, size_t destsize );
+size_t Q_strcat( char *dest, size_t destsize, const char *src );
+size_t Q_concat( char *dest, size_t destsize, ... ) q_sentinel;
+size_t Com_sprintf( char *dest, size_t destsize, const char *fmt, ... ) q_printf( 3, 4 );
+size_t Q_vsnprintf( char *dest, size_t destsize, const char *fmt, va_list argptr );
void Com_PageInMemory (void *buffer, int size);
diff --git a/source/r_bsp.c b/source/r_bsp.c
index 35a6521..82d2372 100644
--- a/source/r_bsp.c
+++ b/source/r_bsp.c
@@ -587,7 +587,7 @@ void Bsp_LoadWorld( const char *path ) {
lump_t *lump;
int i;
byte *data;
- unsigned length, endpos;
+ size_t length, endpos;
length = fs.LoadFileEx( path, ( void ** )&data, FS_FLAG_CACHE );
if( !data ) {
diff --git a/source/r_images.c b/source/r_images.c
index c5797ca..a0651b6 100644
--- a/source/r_images.c
+++ b/source/r_images.c
@@ -68,7 +68,7 @@ Image_LoadPCX
void Image_LoadPCX( const char *filename, byte **pic, byte *palette, int *width, int *height ) {
byte *raw, *end;
pcx_t *pcx;
- unsigned len, x, y, w, h;
+ size_t len, x, y, w, h;
int dataByte, runLength;
byte *out, *pix;
@@ -460,7 +460,7 @@ void Image_LoadTGA( const char *filename, byte **pic,
int *width, int *height )
{
byte *buffer;
- int length;
+ size_t length;
byte *pixels;
int offset, w, h;
qboolean (*decode)( byte *, byte *, int, int, byte * );
@@ -677,7 +677,7 @@ METHODDEF( void )mem_skip_input_data( j_decompress_ptr cinfo, long num_bytes ) {
METHODDEF( void )mem_term_source( j_decompress_ptr cinfo ) { }
-METHODDEF( void )jpeg_mem_src( j_decompress_ptr cinfo, byte *data, int size ) {
+METHODDEF( void )jpeg_mem_src( j_decompress_ptr cinfo, byte *data, size_t size ) {
cinfo->src = ( struct jpeg_source_mgr * )(*cinfo->mem->alloc_small)(
( j_common_ptr )cinfo, JPOOL_PERMANENT, sizeof( struct jpeg_source_mgr ) );
@@ -701,7 +701,7 @@ void Image_LoadJPG( const char *filename, byte **pic, int *width, int *height )
JSAMPARRAY buffer;
int row_stride;
byte *rawdata;
- int rawlength;
+ size_t rawlength;
byte *pixels;
byte *src;
uint32_t *dst;
@@ -954,7 +954,7 @@ LoadPNG
*/
void Image_LoadPNG( const char *filename, byte **pic, int *width, int *height ) {
byte *rawdata;
- int rawlength;
+ size_t rawlength;
byte *pixels;
png_bytep row_pointers[MAX_TEXTURE_SIZE];
png_uint_32 w, h, rowbytes, row;
@@ -1293,7 +1293,7 @@ Case and extension insensitive.
===============
*/
static image_t *R_LookupImage( const char *name, imagetype_t type,
- unsigned hash, int baselength )
+ unsigned hash, size_t baselength )
{
image_t *image;
@@ -1315,7 +1315,7 @@ image_t *R_AllocImage( const char *name ) {
char *ext;
unsigned hash;
image_t *image;
- int length;
+ size_t length;
if( !name || !name[0] ) {
Com_Error( ERR_FATAL, "R_AllocImage: NULL" );
@@ -1323,10 +1323,10 @@ image_t *R_AllocImage( const char *name ) {
length = strlen( name );
if( length >= MAX_QPATH ) {
- Com_Error( ERR_FATAL, "R_AllocImage: oversize name: %d chars", length );
+ Com_Error( ERR_FATAL, "R_AllocImage: oversize name" );
}
- strcpy( buffer, name );
+ memcpy( buffer, name, length + 1 );
ext = COM_FileExtension( buffer );
if( *ext == '.' ) {
@@ -1372,7 +1372,7 @@ image_t *R_FindImage( const char *name, imagetype_t type ) {
int width, height;
char buffer[MAX_QPATH];
char *ext, *s;
- int length;
+ size_t length;
unsigned hash, extHash;
imageflags_t flags;
@@ -1382,7 +1382,7 @@ image_t *R_FindImage( const char *name, imagetype_t type ) {
length = strlen( name );
if( length >= MAX_QPATH ) {
- Com_Error( ERR_FATAL, "R_FindImage: oversize name: %d chars", length );
+ Com_Error( ERR_FATAL, "R_FindImage: oversize name" );
}
if( length <= 4 ) {
diff --git a/source/ref_public.h b/source/ref_public.h
index 8e4dce3..2484a92 100644
--- a/source/ref_public.h
+++ b/source/ref_public.h
@@ -209,7 +209,7 @@ typedef struct refAPI_s {
void (*SetClipRect)( int flags, const clipRect_t *clip );
void (*SetScale)( float *scale );
void (*DrawChar)( int x, int y, int flags, int ch, qhandle_t hFont );
- int (*DrawString)( int x, int y, int flags, int maxChars,
+ int (*DrawString)( int x, int y, int flags, size_t maxChars,
const char *string, qhandle_t hFont ); // returns advanced x coord
// will return 0 0 if not found
void (*DrawGetPicSize)( int *w, int *h, qhandle_t hPic );
diff --git a/source/snd_mem.c b/source/snd_mem.c
index 8e2593c..3eddb28 100644
--- a/source/snd_mem.c
+++ b/source/snd_mem.c
@@ -301,7 +301,7 @@ sfxcache_t *S_LoadSound (sfx_t *s) {
byte *data;
wavinfo_t info;
sfxcache_t *sc;
- int size;
+ size_t size;
char *name;
if (s->name[0] == '*')
diff --git a/source/sv_ac.c b/source/sv_ac.c
index 5329a7a..d01eae8 100644
--- a/source/sv_ac.c
+++ b/source/sv_ac.c
@@ -93,7 +93,7 @@ typedef struct {
qboolean ping_pending;
unsigned last_ping;
netstream_t stream;
- int msglen;
+ size_t msglen;
} ac_locals_t;
typedef struct {
@@ -271,7 +271,8 @@ static void AC_ParseCvar( const char *data, int linenum, const char *path ) {
int num_values, namelen, vallen, deflen;
ac_cvar_t *cvar;
const ac_cvarop_t *op;
- int i, len;
+ int i;
+ size_t len;
name = COM_SimpleParse( &data, &namelen );
if( !name[0] ) {
@@ -324,7 +325,7 @@ static void AC_ParseCvar( const char *data, int linenum, const char *path ) {
return;
}
values[num_values] = val;
- lengths[num_values++] = len + 1;
+ lengths[num_values++] = ( byte )( len + 1 );
if( !p ) {
break;
}
@@ -352,7 +353,7 @@ static void AC_ParseCvar( const char *data, int linenum, const char *path ) {
static void AC_ParseToken( const char *data, int linenum, const char *path ) {
string_entry_t *tok;
- int len = strlen( data );
+ size_t len = strlen( data );
tok = SV_Malloc( sizeof( *tok ) + len );
memcpy( tok->string, data, len + 1 );
@@ -525,16 +526,16 @@ static void AC_Disable( void ) {
static void AC_Announce( client_t *client, const char *fmt, ... ) {
va_list argptr;
char string[MAX_STRING_CHARS];
- int length;
+ size_t len;
va_start( argptr, fmt );
- length = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
+ len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr );
MSG_WriteByte( svc_print );
MSG_WriteByte( PRINT_HIGH );
MSG_WriteData( AC_MESSAGE, sizeof( AC_MESSAGE ) - 1 );
- MSG_WriteData( string, length + 1 );
+ MSG_WriteData( string, len + 1 );
if( client->state == cs_spawned ) {
FOR_EACH_CLIENT( client ) {
@@ -681,7 +682,8 @@ static void AC_ParseFileViolation( void ) {
string_entry_t *bad;
client_t *cl;
char *path, *hash;
- int action, pathlen;
+ int action;
+ size_t pathlen;
ac_file_t *f;
cl = AC_ParseClient();
@@ -818,7 +820,7 @@ static void AC_ParseDisconnect ( void ) {
static qboolean AC_ParseMessage( void ) {
uint16_t msglen;
byte *data;
- int length;
+ size_t length;
int cmd;
// parse msglen
@@ -831,7 +833,7 @@ static qboolean AC_ParseMessage( void ) {
}
msglen = LittleShort( msglen );
if( msglen > AC_RECV_SIZE ) {
- Com_EPrintf( "ANTICHEAT: Oversize message: %d bytes\n", msglen );
+ Com_EPrintf( "ANTICHEAT: Oversize message: %u bytes\n", msglen );
AC_Drop();
return qfalse;
}
@@ -919,7 +921,7 @@ IN-GAME QUERIES
static void AC_Write( const char *func ) {
byte *src = msg_write.data;
- int len = msg_write.cursize;
+ size_t len = msg_write.cursize;
SZ_Clear( &msg_write );
@@ -1097,7 +1099,7 @@ STARTUP STUFF
static qboolean AC_Flush( void ) {
byte *src = msg_write.data;
- int ret, len = msg_write.cursize;
+ size_t ret, len = msg_write.cursize;
SZ_Clear( &msg_write );
@@ -1130,7 +1132,7 @@ static qboolean AC_Flush( void ) {
}
static void AC_WriteString( const char *s ) {
- int len = strlen( s );
+ size_t len = strlen( s );
if( len > 255 ) {
len = 255;
@@ -1197,8 +1199,8 @@ static void AC_SendPing( void ) {
}
static void AC_SendHello( void ) {
- int hostlen = strlen( sv_hostname->string );
- int verlen = strlen( com_version->string );
+ size_t hostlen = strlen( sv_hostname->string );
+ size_t verlen = strlen( com_version->string );
MSG_WriteByte( 0x02 );
MSG_WriteShort( 22 + hostlen + verlen ); // why 22 instead of 9?
diff --git a/source/sv_ccmds.c b/source/sv_ccmds.c
index 3625b31..1519f87 100644
--- a/source/sv_ccmds.c
+++ b/source/sv_ccmds.c
@@ -297,7 +297,7 @@ static void SV_DumpUdpClients( void ) {
Com_Printf( "%7u ", svs.realtime - client->lastmessage );
Com_Printf( "%-21s ", NET_AdrToString(
&client->netchan->remote_address ) );
- Com_Printf( "%5i ", client->rate );
+ Com_Printf( "%5"PRIz" ", client->rate );
Com_Printf( "%2i ", client->protocol );
Com_Printf( "\n" );
}
@@ -327,7 +327,7 @@ static void SV_DumpTcpClients( void ) {
"--- -------------------- --- ------- --------------------- -----\n" );
count = 0;
LIST_FOR_EACH( tcpClient_t, client, &svs.tcp_client_list, entry ) {
- Com_Printf( "%3d %-20.20s %3d %7u %-21s ",
+ Com_Printf( "%3d %-20.20s %3"PRIz" %7u %-21s ",
count, client->resource ? client->resource : "",
FIFO_Usage( &client->stream.send ),
svs.realtime - client->lastmessage,
@@ -787,14 +787,14 @@ static void SV_ListBans_f( void ) {
SV_ListMatches_f( &sv_banlist );
}
-static int SV_Client_m( char *buffer, int size ) {
+static size_t SV_Client_m( char *buffer, size_t size ) {
if( !sv_client ) {
return Q_strncpyz( buffer, "unknown", size );
}
return Q_strncpyz( buffer, sv_client->name, size );
}
-static int SV_ClientNum_m( char *buffer, int size ) {
+static size_t SV_ClientNum_m( char *buffer, size_t size ) {
if( !sv_client ) {
return Q_strncpyz( buffer, "", size );
}
diff --git a/source/sv_game.c b/source/sv_game.c
index 4cee66d..21aeceb 100644
--- a/source/sv_game.c
+++ b/source/sv_game.c
@@ -157,11 +157,11 @@ static void PF_bprintf( int level, const char *fmt, ... ) {
va_list argptr;
char string[MAX_STRING_CHARS];
client_t *client;
- int length;
+ size_t len;
int i;
va_start( argptr, fmt );
- length = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
+ len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr );
if( svs.mvd.dummy && sv.mvd.paused < PAUSED_FRAMES ) {
@@ -170,12 +170,12 @@ static void PF_bprintf( int level, const char *fmt, ... ) {
MSG_WriteByte( svc_print );
MSG_WriteByte( level );
- MSG_WriteData( string, length + 1 );
+ MSG_WriteData( string, len + 1 );
// echo to console
if( dedicated->integer ) {
// mask off high bits
- for( i = 0; i < length; i++ )
+ for( i = 0; i < len; i++ )
string[i] &= 127;
Com_Printf( "%s", string );
}
@@ -222,11 +222,12 @@ Archived in MVD stream.
static void PF_cprintf( edict_t *ent, int level, const char *fmt, ... ) {
char msg[MAX_STRING_CHARS];
va_list argptr;
- int clientNum, length;
+ int clientNum;
+ size_t len;
client_t *client;
va_start( argptr, fmt );
- length = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
+ len = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
va_end( argptr );
if( !ent ) {
@@ -246,7 +247,7 @@ static void PF_cprintf( edict_t *ent, int level, const char *fmt, ... ) {
MSG_WriteByte( svc_print );
MSG_WriteByte( level );
- MSG_WriteData( msg, length + 1 );
+ MSG_WriteData( msg, len + 1 );
if( level >= client->messagelevel ) {
SV_ClientAddMessage( client, MSG_RELIABLE );
@@ -273,7 +274,8 @@ Archived in MVD stream.
static void PF_centerprintf( edict_t *ent, const char *fmt, ... ) {
char msg[MAX_STRING_CHARS];
va_list argptr;
- int n, length;
+ int n;
+ size_t len;
if( !ent ) {
return;
@@ -286,11 +288,11 @@ static void PF_centerprintf( edict_t *ent, const char *fmt, ... ) {
}
va_start( argptr, fmt );
- length = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
+ len = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
va_end( argptr );
MSG_WriteByte( svc_centerprint );
- MSG_WriteData( msg, length + 1 );
+ MSG_WriteData( msg, len + 1 );
PF_Unicast( ent, qtrue );
}
@@ -352,7 +354,7 @@ Archived in MVD stream.
===============
*/
void PF_Configstring( int index, const char *val ) {
- int length, maxlength;
+ size_t length, maxlength;
client_t *client;
if( index < 0 || index >= MAX_CONFIGSTRINGS )
@@ -364,7 +366,7 @@ void PF_Configstring( int index, const char *val ) {
length = strlen( val );
maxlength = sizeof( sv.configstrings ) - MAX_QPATH * index;
if( length >= maxlength ) {
- Com_Error( ERR_DROP, "%s: index %d overflowed: %d > %d\n", __func__,
+ Com_Error( ERR_DROP, "%s: index %d overflowed: %"PRIz" > %"PRIz"\n", __func__,
index, length, maxlength - 1 );
}
diff --git a/source/sv_http.c b/source/sv_http.c
index 8123a32..0c2c5cf 100644
--- a/source/sv_http.c
+++ b/source/sv_http.c
@@ -275,7 +275,7 @@ static const uriEntry_t rootURIs[] = {
void SV_HttpHandle( const uriEntry_t *e, const char *uri ) {
const char *p;
- int length;
+ size_t length;
if( *uri == '/' ) {
uri++;
@@ -301,7 +301,7 @@ void SV_HttpHandle( const uriEntry_t *e, const char *uri ) {
}
}
-void SV_HttpWrite( tcpClient_t *client, void *data, int length ) {
+void SV_HttpWrite( tcpClient_t *client, void *data, size_t len ) {
fifo_t *fifo = &client->stream.send;
if( client->state <= cs_zombie ) {
@@ -318,26 +318,26 @@ void SV_HttpWrite( tcpClient_t *client, void *data, int length ) {
}
z->next_in = data;
- z->avail_in = length;
+ z->avail_in = ( uInt )len;
while( z->avail_in ) {
- data = FIFO_Reserve( fifo, &length );
- if( !length ) {
+ data = FIFO_Reserve( fifo, &len );
+ if( !len ) {
SV_HttpDrop( client, "overflowed" );
return;
}
z->next_out = data;
- z->avail_out = length;
+ z->avail_out = ( uInt )len;
if( deflate( z, param ) != Z_OK ) {
SV_HttpDrop( client, "deflate failed" );
return;
}
- length -= z->avail_out;
- if( length > 0 ) {
- FIFO_Commit( fifo, length );
+ len -= z->avail_out;
+ if( len > 0 ) {
+ FIFO_Commit( fifo, len );
client->noflush = 0;
}
}
@@ -345,7 +345,7 @@ void SV_HttpWrite( tcpClient_t *client, void *data, int length ) {
}
#endif
- if( !FIFO_TryWrite( fifo, data, length ) ) {
+ if( !FIFO_TryWrite( fifo, data, len ) ) {
SV_HttpDrop( client, "overflowed" );
}
}
@@ -355,7 +355,8 @@ void SV_HttpFinish( tcpClient_t *client ) {
fifo_t *fifo = &client->stream.send;
z_streamp z = &client->z;
byte *data;
- int length, ret;
+ size_t len;
+ int ret;
if( client->state <= cs_zombie ) {
return;
@@ -369,18 +370,18 @@ void SV_HttpFinish( tcpClient_t *client ) {
z->avail_in = 0;
do {
- data = FIFO_Reserve( fifo, &length );
- if( !length ) {
+ data = FIFO_Reserve( fifo, &len );
+ if( !len ) {
SV_HttpDrop( client, "overflowed" );
return;
}
z->next_out = data;
- z->avail_out = length;
+ z->avail_out = ( uInt )len;
ret = deflate( z, Z_FINISH );
- FIFO_Commit( fifo, length - z->avail_out );
+ FIFO_Commit( fifo, len - z->avail_out );
} while( ret == Z_OK );
if( ret != Z_STREAM_END ) {
@@ -392,17 +393,17 @@ void SV_HttpFinish( tcpClient_t *client ) {
void SV_HttpPrintf( const char *fmt, ... ) {
char buffer[MAX_STRING_CHARS];
va_list argptr;
- int length;
+ size_t len;
if( http_client->state <= cs_zombie ) {
return;
}
va_start( argptr, fmt );
- length = Q_vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
+ len = Q_vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
va_end( argptr );
- if( FIFO_Write( &http_client->stream.send, buffer, length ) != length ) {
+ if( FIFO_Write( &http_client->stream.send, buffer, len ) != len ) {
SV_HttpDrop( http_client, "overflowed" );
}
}
@@ -529,7 +530,7 @@ static qboolean SV_HttpParseRequest( tcpClient_t *client ) {
char *p, *token;
const char *line;
byte *b, *data;
- int length;
+ size_t length;
int major, minor;
while( 1 ) {
diff --git a/source/sv_local.h b/source/sv_local.h
index 702aff0..0a14cb4 100644
--- a/source/sv_local.h
+++ b/source/sv_local.h
@@ -176,8 +176,8 @@ typedef struct client_s {
int frame_latency[LATENCY_COUNTS];
int ping;
- int message_size[RATE_MESSAGES]; // used to rate drop packets
- int rate;
+ size_t message_size[RATE_MESSAGES]; // used to rate drop packets
+ size_t rate;
int surpressCount; // number of messages rate supressed
unsigned send_time, send_delta; // used to rate drop async packets
frameflags_t frameflags;
@@ -229,7 +229,7 @@ typedef struct client_s {
int slot;
// netchan type dependent methods
- void (*AddMessage)( struct client_s *, byte *, int, qboolean );
+ void (*AddMessage)( struct client_s *, byte *, size_t, qboolean );
void (*WriteFrame)( struct client_s * );
void (*FinishFrame)( struct client_s * );
void (*WriteDatagram)( struct client_s * );
@@ -273,7 +273,7 @@ typedef struct {
unsigned lastmessage;
char request[MAX_NET_STRING];
- int requestLength;
+ size_t requestLength;
htmethod_t method;
char *resource, *host, *agent, *credentials;
@@ -455,7 +455,7 @@ typedef enum {RD_NONE, RD_CLIENT, RD_PACKET} redirect_t;
extern char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
-void SV_FlushRedirect( int redirected, char *outputbuf, int length );
+void SV_FlushRedirect( int redirected, char *outputbuf, size_t len );
void SV_DemoCompleted (void);
void SV_SendClientMessages (void);
@@ -470,16 +470,16 @@ void SV_PacketizedClear( client_t *client );
void SV_OldClientWriteDatagram( client_t *client );
void SV_OldClientAddMessage( client_t *client, byte *data,
- int length, qboolean reliable );
-void SV_OldClientWriteReliableMessages( client_t *client, int maxSize );
+ size_t length, qboolean reliable );
+void SV_OldClientWriteReliableMessages( client_t *client, size_t maxsize );
void SV_OldClientFinishFrame( client_t *client );
void SV_NewClientWriteDatagram( client_t *client );
void SV_NewClientAddMessage( client_t *client, byte *data,
- int length, qboolean reliable );
+ size_t length, qboolean reliable );
void SV_NewClientFinishFrame( client_t *client );
-void SV_CalcSendTime( client_t *client, int messageSize );
+void SV_CalcSendTime( client_t *client, size_t messageSize );
//
// sv_mvd.c
@@ -518,7 +518,7 @@ void SV_HttpRun( void );
void SV_HttpRemove( tcpClient_t *client );
void SV_HttpDrop( tcpClient_t *client, const char *error );
-void SV_HttpWrite( tcpClient_t *client, void *data, int length );
+void SV_HttpWrite( tcpClient_t *client, void *data, size_t length );
void SV_HttpFinish( tcpClient_t *client );
void SV_HttpPrintf( const char *fmt, ... ) q_printf( 1, 2 );
diff --git a/source/sv_main.c b/source/sv_main.c
index 85489e0..b27e75d 100644
--- a/source/sv_main.c
+++ b/source/sv_main.c
@@ -273,10 +273,11 @@ SV_StatusString
Builds the string that is sent as heartbeats and status replies
===============
*/
-static int SV_StatusString( char *status ) {
+static size_t SV_StatusString( char *status ) {
char entry[MAX_STRING_CHARS];
client_t *cl;
- int j, total, length;
+ int j;
+ size_t total, length;
char *tmp = sv_maxclients->string;
// XXX: ugly hack to hide reserved slots
@@ -331,17 +332,17 @@ static int SV_StatusString( char *status ) {
static void q_printf( 1, 2 ) SV_OobPrintf( const char *format, ... ) {
va_list argptr;
char buffer[MAX_PACKETLEN_DEFAULT];
- int length;
+ size_t len;
// write the packet header
memcpy( buffer, "\xff\xff\xff\xffprint\n", 10 );
va_start( argptr, format );
- length = Q_vsnprintf( buffer + 10, sizeof( buffer ) - 10, format, argptr );
+ len = Q_vsnprintf( buffer + 10, sizeof( buffer ) - 10, format, argptr );
va_end( argptr );
// send the datagram
- NET_SendPacket( NS_SERVER, &net_from, length + 10, buffer );
+ NET_SendPacket( NS_SERVER, &net_from, len + 10, buffer );
}
@@ -354,7 +355,7 @@ Responds with all the info that qplug or qspy can see
*/
static void SVC_Status( void ) {
char buffer[MAX_PACKETLEN_DEFAULT];
- int length;
+ size_t len;
if( !sv_status_show->integer ) {
return;
@@ -371,10 +372,10 @@ static void SVC_Status( void ) {
// write the packet header
memcpy( buffer, "\xff\xff\xff\xffprint\n", 10 );
- length = SV_StatusString( buffer + 10 );
+ len = SV_StatusString( buffer + 10 );
// send the datagram
- NET_SendPacket( NS_SERVER, &net_from, length + 10, buffer );
+ NET_SendPacket( NS_SERVER, &net_from, len + 10, buffer );
}
/*
@@ -408,7 +409,7 @@ The second parameter should be the current protocol version number.
*/
static void SVC_Info( void ) {
char string[MAX_QPATH];
- int length;
+ size_t len;
int count;
int version;
client_t *client;
@@ -428,12 +429,12 @@ static void SVC_Info( void ) {
count++;
}
- length = Com_sprintf (string, sizeof(string),
+ len = Com_sprintf (string, sizeof(string),
"\xff\xff\xff\xffinfo\n%16s %8s %2i/%2i\n",
sv_hostname->string, sv.name, count, sv_maxclients->integer -
sv_reserved_slots->integer );
- NET_SendPacket( NS_SERVER, &net_from, length, string );
+ NET_SendPacket( NS_SERVER, &net_from, len, string );
}
/*
@@ -506,7 +507,8 @@ static void SVC_DirectConnect( void ) {
char userinfo[MAX_INFO_STRING];
char reconnect_var[16];
char reconnect_val[16];
- int i, number, count, length;
+ int i, number, count;
+ size_t length;
client_t *cl, *newcl, *lastcl;
int protocol, version;
int qport;
@@ -692,8 +694,8 @@ static void SVC_DirectConnect( void ) {
length = strlen( s );
if( length > MAX_CLIENT_NAME - 1 ) {
SV_OobPrintf( "Names longer than %d characters are not allowed.\n"
- "Your name is %d characters long.\n", MAX_CLIENT_NAME - 1, length );
- Com_DPrintf( " rejected - oversize name (%d chars).\n", length );
+ "Your name is %"PRIz" characters long.\n", MAX_CLIENT_NAME - 1, length );
+ Com_DPrintf( " rejected - oversize name (%"PRIz" chars).\n", length );
return;
}
@@ -1238,7 +1240,7 @@ void SV_SendAsyncPackets( void ) {
qboolean retransmit;
client_t *client;
netchan_t *netchan;
- int cursize;
+ size_t cursize;
FOR_EACH_CLIENT( client ) {
// don't overrun bandwidth
@@ -1252,7 +1254,7 @@ void SV_SendAsyncPackets( void ) {
if( netchan->fragment_pending ) {
cursize = netchan->TransmitNextFragment( netchan );
if( sv_debug_send->integer ) {
- Com_Printf( S_COLOR_BLUE"%s: frag: %d\n",
+ Com_Printf( S_COLOR_BLUE"%s: frag: %"PRIz"\n",
client->name, cursize );
}
goto calctime;
@@ -1280,7 +1282,7 @@ void SV_SendAsyncPackets( void ) {
{
cursize = netchan->Transmit( netchan, 0, NULL );
if( sv_debug_send->integer ) {
- Com_Printf( S_COLOR_BLUE"%s: send: %d\n",
+ Com_Printf( S_COLOR_BLUE"%s: send: %"PRIz"\n",
client->name, cursize );
}
calctime:
@@ -1386,7 +1388,7 @@ static void SV_RunGameFrame( void ) {
ge->RunFrame();
if( msg_write.cursize ) {
- Com_WPrintf( "Game DLL left %d bytes in multicast buffer, cleared.\n",
+ Com_WPrintf( "Game DLL left %"PRIz" bytes in multicast buffer, cleared.\n",
msg_write.cursize );
SZ_Clear( &msg_write );
}
@@ -1419,7 +1421,7 @@ let it know we are alive, and log information
*/
static void SV_MasterHeartbeat( void ) {
char buffer[MAX_PACKETLEN_DEFAULT];
- int length;
+ size_t len;
int i;
if( !dedicated->integer )
@@ -1437,14 +1439,14 @@ static void SV_MasterHeartbeat( void ) {
memcpy( buffer, "\xff\xff\xff\xffheartbeat\n", 14 );
// send the same string that we would give for a status OOB command
- length = SV_StatusString( buffer + 14 );
+ len = SV_StatusString( buffer + 14 );
// send to group master
for( i = 0; i < MAX_MASTERS; i++ ) {
if( master_adr[i].port ) {
Com_DPrintf( "Sending heartbeat to %s\n",
NET_AdrToString( &master_adr[i] ) );
- NET_SendPacket( NS_SERVER, &master_adr[i], length + 14, buffer );
+ NET_SendPacket( NS_SERVER, &master_adr[i], len + 14, buffer );
}
}
}
@@ -1580,7 +1582,7 @@ WARNING: may modify userinfo in place!
*/
void SV_UpdateUserinfo( char *userinfo ) {
char *s;
- int len;
+ size_t len;
if( !userinfo[0] ) {
SV_DropClient( sv_client, "empty userinfo" );
@@ -1634,7 +1636,8 @@ into a more C freindly form.
void SV_UserinfoChanged( client_t *cl ) {
char name[MAX_CLIENT_NAME];
char *val;
- int i, len;
+ size_t len;
+ int i;
// call prog code to allow overrides
ge->ClientUserinfoChanged( cl->edict, cl->userinfo );
diff --git a/source/sv_mvd.c b/source/sv_mvd.c
index 5ef28ae..007f1f0 100644
--- a/source/sv_mvd.c
+++ b/source/sv_mvd.c
@@ -315,7 +315,7 @@ static void SV_DummyExecuteString( const char *line ) {
}
static void SV_DummyAddMessage( client_t *client, byte *data,
- int length, qboolean reliable )
+ size_t length, qboolean reliable )
{
tcpClient_t *t;
@@ -488,7 +488,8 @@ into the multicast buffer.
*/
void SV_MvdBeginFrame( void ) {
int i, j;
- int index, length;
+ int index;
+ size_t length;
client_t *client;
qboolean found;
@@ -544,7 +545,7 @@ void SV_MvdBeginFrame( void ) {
}
}
- Com_Printf( "MVD stream resumed, flushed %d bytes.\n",
+ Com_Printf( "MVD stream resumed, flushed %"PRIz" bytes.\n",
sv.mvd.message.cursize );
// will be subsequently written to disk by SV_MvdEndFrame
}
@@ -589,13 +590,13 @@ void SV_MvdEndFrame( void ) {
// check if frame fits
if( sv.mvd.message.cursize + msg_write.cursize > MAX_MSGLEN ) {
- Com_WPrintf( "Dumping MVD frame: %d bytes\n", msg_write.cursize );
+ Com_WPrintf( "Dumping MVD frame: %"PRIz" bytes\n", msg_write.cursize );
SZ_Clear( &msg_write );
}
// check if unreliable datagram fits
if( sv.mvd.message.cursize + msg_write.cursize + sv.mvd.datagram.cursize > MAX_MSGLEN ) {
- Com_WPrintf( "Dumping MVD datagram: %d bytes\n", sv.mvd.datagram.cursize );
+ Com_WPrintf( "Dumping MVD datagram: %"PRIz" bytes\n", sv.mvd.datagram.cursize );
SZ_Clear( &sv.mvd.datagram );
}
@@ -655,7 +656,7 @@ static void SV_MvdEmitGamestate( void ) {
int i, j;
player_state_t *ps;
entity_state_t *es;
- int length;
+ size_t length;
uint16_t *patch;
int flags, extra, portalbytes;
byte portalbits[MAX_MAP_AREAS/8];
diff --git a/source/sv_send.c b/source/sv_send.c
index 213b976..a591b78 100644
--- a/source/sv_send.c
+++ b/source/sv_send.c
@@ -32,17 +32,17 @@ MISC
char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
-void SV_FlushRedirect( int redirected, char *outputbuf, int length ) {
+void SV_FlushRedirect( int redirected, char *outputbuf, size_t len ) {
byte buffer[MAX_PACKETLEN_DEFAULT];
if( redirected == RD_PACKET ) {
memcpy( buffer, "\xff\xff\xff\xffprint\n", 10 );
- memcpy( buffer + 10, outputbuf, length );
- NET_SendPacket( NS_SERVER, &net_from, length + 10, buffer );
+ memcpy( buffer + 10, outputbuf, len );
+ NET_SendPacket( NS_SERVER, &net_from, len + 10, buffer );
} else if( redirected == RD_CLIENT ) {
MSG_WriteByte( svc_print );
MSG_WriteByte( PRINT_HIGH );
- MSG_WriteData( outputbuf, length );
+ MSG_WriteData( outputbuf, len );
MSG_WriteByte( 0 );
//Sys_Printf("redirect: %d bytes: %s", outputbuf);
SV_ClientAddMessage( sv_client, MSG_RELIABLE|MSG_CLEAR );
@@ -58,7 +58,7 @@ bandwidth estimation and should not be sent another packet
=======================
*/
static qboolean SV_RateDrop( client_t *client ) {
- int total;
+ size_t total;
int i;
// never drop over the loopback
@@ -80,11 +80,7 @@ static qboolean SV_RateDrop( client_t *client ) {
return qfalse;
}
-void SV_CalcSendTime( client_t *client, int size ) {
- if( size == -1 ) {
- return;
- }
-
+void SV_CalcSendTime( client_t *client, size_t size ) {
// never drop over the loopback
if( !client->rate ) {
client->send_time = svs.realtime;
@@ -118,18 +114,18 @@ NOT archived in MVD stream.
void SV_ClientPrintf( client_t *client, int level, const char *fmt, ... ) {
va_list argptr;
char string[MAX_STRING_CHARS];
- int length;
+ size_t len;
if( level < client->messagelevel )
return;
va_start( argptr, fmt );
- length = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
+ len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr );
MSG_WriteByte( svc_print );
MSG_WriteByte( level );
- MSG_WriteData( string, length + 1 );
+ MSG_WriteData( string, len + 1 );
SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR );
}
@@ -146,15 +142,15 @@ void SV_BroadcastPrintf( int level, const char *fmt, ... ) {
va_list argptr;
char string[MAX_STRING_CHARS];
client_t *client;
- int length;
+ size_t len;
va_start( argptr, fmt );
- length = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
+ len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr );
MSG_WriteByte( svc_print );
MSG_WriteByte( level );
- MSG_WriteData( string, length + 1 );
+ MSG_WriteData( string, len + 1 );
FOR_EACH_CLIENT( client ) {
if( client->state != cs_spawned )
@@ -170,14 +166,14 @@ void SV_BroadcastPrintf( int level, const char *fmt, ... ) {
void SV_ClientCommand( client_t *client, const char *fmt, ... ) {
va_list argptr;
char string[MAX_STRING_CHARS];
- int length;
+ size_t len;
va_start( argptr, fmt );
- length = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
+ len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr );
MSG_WriteByte( svc_stufftext );
- MSG_WriteData( string, length + 1 );
+ MSG_WriteData( string, len + 1 );
SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR );
}
@@ -194,14 +190,14 @@ void SV_BroadcastCommand( const char *fmt, ... ) {
va_list argptr;
char string[MAX_STRING_CHARS];
client_t *client;
- int length;
+ size_t len;
va_start( argptr, fmt );
- length = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
+ len = Q_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr );
MSG_WriteByte( svc_stufftext );
- MSG_WriteData( string, length + 1 );
+ MSG_WriteData( string, len + 1 );
FOR_EACH_CLIENT( client ) {
SV_ClientAddMessage( client, MSG_RELIABLE );
@@ -327,7 +323,7 @@ unless told otherwise.
*/
void SV_ClientAddMessage( client_t *client, int flags ) {
if( sv_debug_send->integer > 1 ) {
- Com_Printf( S_COLOR_BLUE"%s: add%c: %d\n", client->name,
+ Com_Printf( S_COLOR_BLUE"%s: add%c: %"PRIz"\n", client->name,
( flags & MSG_RELIABLE ) ? 'r' : 'u', msg_write.cursize );
}
@@ -370,12 +366,15 @@ void SV_PacketizedClear( client_t *client ) {
}
message_packet_t *SV_PacketizedAdd( client_t *client, byte *data,
- int length, qboolean reliable )
+ size_t len, qboolean reliable )
{
message_packet_t *msg;
- if( length > MSG_TRESHOLD ) {
- msg = SV_Malloc( sizeof( *msg ) + length - MSG_TRESHOLD );
+ if( len > MSG_TRESHOLD ) {
+ if( len > MAX_MSGLEN ) {
+ Com_Error( ERR_FATAL, "%s: oversize packet", __func__ );
+ }
+ msg = SV_Malloc( sizeof( *msg ) + len - MSG_TRESHOLD );
} else {
if( LIST_EMPTY( &client->msg_free ) ) {
Com_WPrintf( "Out of message slots for %s!\n", client->name );
@@ -389,15 +388,15 @@ message_packet_t *SV_PacketizedAdd( client_t *client, byte *data,
List_Remove( &msg->entry );
}
- memcpy( msg->data, data, length );
- msg->cursize = length;
+ memcpy( msg->data, data, len );
+ msg->cursize = ( uint16_t )len;
List_Append( &client->msg_used[reliable], &msg->entry );
return msg;
}
-static void SV_AddClientSounds( client_t *client, int maxsize ) {
+static void SV_AddClientSounds( client_t *client, size_t maxsize ) {
sound_packet_t *msg, *next;
edict_t *edict;
entity_state_t *state;
@@ -489,9 +488,9 @@ FRAME UPDATES - DEFAULT, R1Q2 AND Q2PRO CLIENTS (OLD NETCHAN)
#define FOR_EACH_MSG( list ) LIST_FOR_EACH_SAFE( message_packet_t, msg, next, list, entry )
void SV_OldClientAddMessage( client_t *client, byte *data,
- int length, qboolean reliable )
+ size_t len, qboolean reliable )
{
- if( length > client->netchan->maxpacketlen ) {
+ if( len > client->netchan->maxpacketlen ) {
if( reliable ) {
SV_DropClient( client, "oversize reliable message" );
} else {
@@ -500,7 +499,7 @@ void SV_OldClientAddMessage( client_t *client, byte *data,
return;
}
- SV_PacketizedAdd( client, data, length, reliable );
+ SV_PacketizedAdd( client, data, len, reliable );
}
/*
@@ -511,7 +510,7 @@ This should be the only place data is
ever written to client->netchan.message
=======================
*/
-void SV_OldClientWriteReliableMessages( client_t *client, int maxsize ) {
+void SV_OldClientWriteReliableMessages( client_t *client, size_t maxsize ) {
message_packet_t *msg, *next;
int count;
@@ -545,7 +544,7 @@ void SV_OldClientWriteReliableMessages( client_t *client, int maxsize ) {
}
}
-static inline void write_msg( client_t *client, message_packet_t *msg, int maxsize ) {
+static inline void write_msg( client_t *client, message_packet_t *msg, size_t maxsize ) {
// if this msg fits, write it
if( msg_write.cursize + msg->cursize <= maxsize ) {
MSG_WriteData( msg->data, msg->cursize );
@@ -561,7 +560,7 @@ OldClient_SendDatagram
*/
void SV_OldClientWriteDatagram( client_t *client ) {
message_packet_t *msg, *next;
- int cursize, maxsize;
+ size_t maxsize, cursize;
maxsize = client->netchan->maxpacketlen;
if( client->netchan->reliable_length ) {
@@ -581,7 +580,7 @@ void SV_OldClientWriteDatagram( client_t *client ) {
client->WriteFrame( client );
if( msg_write.cursize > maxsize ) {
if( sv_debug_send->integer ) {
- Com_Printf( S_COLOR_BLUE"Frame overflowed for %s: %d > %d\n",
+ Com_Printf( S_COLOR_BLUE"Frame overflowed for %s: %"PRIz" > %"PRIz"\n",
client->name, msg_write.cursize, maxsize );
}
SZ_Clear( &msg_write );
@@ -665,15 +664,14 @@ FRAME UPDATES - Q2PRO CLIENTS (NEW NETCHAN)
*/
void SV_NewClientAddMessage( client_t *client, byte *data,
- int length, qboolean reliable )
+ size_t length, qboolean reliable )
{
sizebuf_t *buf = reliable ? &client->netchan->message : &client->datagram;
SZ_Write( buf, data, length );
}
void SV_NewClientWriteDatagram( client_t *client ) {
- int cursize;
- int i;
+ size_t cursize;
// send over all the relevant entity_state_t
// and the player_state_t
@@ -700,12 +698,12 @@ void SV_NewClientWriteDatagram( client_t *client ) {
SV_AddClientSounds( client, msg_write.maxsize );
if( sv_pad_packets->integer ) {
- int pad = msg_write.cursize + sv_pad_packets->integer;
+ size_t pad = msg_write.cursize + sv_pad_packets->integer;
if( pad > msg_write.maxsize ) {
pad = msg_write.maxsize;
}
- for( i = msg_write.cursize; i < pad; i++ ) {
+ for( ; pad > 0; pad-- ) {
MSG_WriteByte( svc_nop );
}
}
@@ -750,7 +748,7 @@ Clients in earlier connection state are handled in SV_SendAsyncPackets.
*/
void SV_SendClientMessages( void ) {
client_t *client;
- int msglen;
+ size_t cursize;
// send a message to each connected client
FOR_EACH_CLIENT( client ) {
@@ -774,8 +772,8 @@ void SV_SendClientMessages( void ) {
} else {
// don't write any frame data until all fragments are sent
if( client->netchan->fragment_pending ) {
- msglen = client->netchan->TransmitNextFragment( client->netchan );
- SV_CalcSendTime( client, msglen );
+ cursize = client->netchan->TransmitNextFragment( client->netchan );
+ SV_CalcSendTime( client, cursize );
} else {
// build the new frame and write it
SV_BuildClientFrame( client );
diff --git a/source/sv_user.c b/source/sv_user.c
index 47c574f..ead7e3f 100644
--- a/source/sv_user.c
+++ b/source/sv_user.c
@@ -84,7 +84,7 @@ static void create_baselines( void ) {
static void write_plain_configstrings( void ) {
int i;
char *string;
- int length;
+ size_t length;
// write a packet full of data
string = sv_client->configstrings;
@@ -144,7 +144,8 @@ static void write_plain_baselines( void ) {
static void write_compressed_gamestate( void ) {
sizebuf_t *buf = &sv_client->netchan->message;
entity_state_t *base;
- int i, j, length;
+ int i, j;
+ size_t length;
uint16_t *patch;
char *string;
@@ -188,9 +189,9 @@ static void write_compressed_gamestate( void ) {
deflateReset( &svs.z );
svs.z.next_in = msg_write.data;
- svs.z.avail_in = msg_write.cursize;
+ svs.z.avail_in = ( uInt )msg_write.cursize;
svs.z.next_out = buf->data + buf->cursize;
- svs.z.avail_out = buf->maxsize - buf->cursize;
+ svs.z.avail_out = ( uInt )( buf->maxsize - buf->cursize );
SZ_Clear( &msg_write );
if( deflate( &svs.z, Z_FINISH ) != Z_STREAM_END ) {
@@ -233,11 +234,12 @@ static inline int z_flush( byte *buffer ) {
static inline void z_reset( byte *buffer ) {
deflateReset( &svs.z );
svs.z.next_out = buffer;
- svs.z.avail_out = sv_client->netchan->maxpacketlen - 5;
+ svs.z.avail_out = ( uInt )( sv_client->netchan->maxpacketlen - 5 );
}
static void write_compressed_configstrings( void ) {
- int i, length;
+ int i;
+ size_t length;
byte buffer[MAX_PACKETLEN_WRITABLE];
char *string;
@@ -269,7 +271,7 @@ static void write_compressed_configstrings( void ) {
MSG_WriteByte( 0 );
svs.z.next_in = msg_write.data;
- svs.z.avail_in = msg_write.cursize;
+ svs.z.avail_in = ( uInt )msg_write.cursize;
SZ_Clear( &msg_write );
if( deflate( &svs.z, Z_SYNC_FLUSH ) != Z_OK ) {
@@ -600,7 +602,7 @@ static void SV_BeginDownload_f( void ) {
downloadsize = FS_LoadFileEx( filename, NULL, FS_FLAG_RAW );
- if( downloadsize == -1 || downloadsize == 0
+ if( downloadsize == INVALID_LENGTH || downloadsize == 0
// special check for maps, if it came from a pak file, don't allow
// download ZOID
|| ( allow == allow_download_maps
diff --git a/source/sw_draw.c b/source/sw_draw.c
index c43d8ef..450a9ff 100644
--- a/source/sw_draw.c
+++ b/source/sw_draw.c
@@ -582,7 +582,7 @@ void Draw_Char( int x, int y, int flags, int ch, qhandle_t hFont ) {
Draw_String
===============
*/
-int Draw_String( int x, int y, int flags, int maxChars,
+int Draw_String( int x, int y, int flags, size_t maxChars,
const char *string, qhandle_t hFont )
{
image_t *image;
diff --git a/source/sw_image.c b/source/sw_image.c
index 13abf48..5e03868 100644
--- a/source/sw_image.c
+++ b/source/sw_image.c
@@ -115,9 +115,8 @@ R_LoadWal
*/
image_t *R_LoadWal( const char *name ) {
miptex_t *mt;
- uint32_t ofs, w, h;
image_t *image;
- unsigned size, length;
+ size_t size, length, ofs, endpos, w, h;
byte *source[4];
length = fs.LoadFile( name, ( void ** )&mt );
@@ -131,7 +130,8 @@ image_t *R_LoadWal( const char *name ) {
size = w * h * ( 256 + 64 + 16 + 4 ) / 256;
ofs = LittleLong( mt->offsets[0] );
- if( ofs + size > length ) {
+ endpos = ofs + size;
+ if( endpos < ofs || endpos > length ) {
Com_DPrintf( "R_LoadWal: %s is malformed\n", name );
fs.FreeFile( ( void * )mt );
return r_notexture_mip;
@@ -301,7 +301,7 @@ R_InitImages
*/
void R_InitImages( void ) {
byte *data;
- int length;
+ size_t length;
registration_sequence = 1;
diff --git a/source/sw_main.c b/source/sw_main.c
index ae006a7..9915fc8 100644
--- a/source/sw_main.c
+++ b/source/sw_main.c
@@ -1361,7 +1361,7 @@ void Draw_FillEx( int x, int y, int w, int h, const color_t color );
void Draw_StretchRaw( int x, int y, int w, int h, int cols,
int rows, const byte *data );
void Draw_Char( int x, int y, int flags, int ch, qhandle_t hFont );
-int Draw_String( int x, int y, int flags, int maxChars,
+int Draw_String( int x, int y, int flags, size_t maxChars,
const char *string, qhandle_t hFont );
/*
diff --git a/source/sys_unix.c b/source/sys_unix.c
index 8b4e96c..b05993f 100644
--- a/source/sys_unix.c
+++ b/source/sys_unix.c
@@ -1024,7 +1024,7 @@ static void Sys_ListFilteredFiles( void **listedFiles,
const char *path,
const char *filter,
int flags,
- int length,
+ size_t length,
int depth )
{
struct dirent *findInfo;
@@ -1107,7 +1107,7 @@ Sys_ListFiles
void **Sys_ListFiles( const char *path,
const char *extension,
int flags,
- int length,
+ size_t length,
int *numFiles )
{
struct dirent *findInfo;
diff --git a/source/sys_win.c b/source/sys_win.c
index d65f3b0..e5764f2 100644
--- a/source/sys_win.c
+++ b/source/sys_win.c
@@ -261,7 +261,7 @@ void Sys_RunConsole( void ) {
case VK_TAB:
Sys_HideInput();
Prompt_CompleteCommand( &sys_con, qfalse );
- f->cursorPos = strlen( f->text );
+ f->cursorPos = ( int )strlen( f->text );
Sys_ShowInput();
break;
default:
@@ -737,7 +737,7 @@ Sys_SetClipboardData
void Sys_SetClipboardData( const char *data ) {
HANDLE clipdata;
char *cliptext;
- int length;
+ size_t length;
if( !data[0] ) {
return;
@@ -910,7 +910,7 @@ static void Sys_ListFilteredFiles( void **listedFiles,
const char *path,
const char *filter,
int flags,
- int length )
+ size_t length )
{
WIN32_FIND_DATAA findInfo;
HANDLE findHandle;
@@ -980,7 +980,7 @@ Sys_ListFiles
void **Sys_ListFiles( const char *rawPath,
const char *extension,
int flags,
- int length,
+ size_t length,
int *numFiles )
{
WIN32_FIND_DATAA findInfo;
@@ -1154,28 +1154,28 @@ reInit:
#if USE_DBGHELP
typedef DWORD (WINAPI *SETSYMOPTIONS)( DWORD );
-typedef BOOL (WINAPI *SYMGETMODULEINFO)( HANDLE, DWORD, PIMAGEHLP_MODULE );
+typedef BOOL (WINAPI *SYMGETMODULEINFO64)( HANDLE, DWORD64, PIMAGEHLP_MODULE64 );
typedef BOOL (WINAPI *SYMINITIALIZE)( HANDLE, PSTR, BOOL );
typedef BOOL (WINAPI *SYMCLEANUP)( HANDLE );
-typedef BOOL (WINAPI *ENUMERATELOADEDMODULES)( HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID );
-typedef BOOL (WINAPI *STACKWALK)( DWORD, HANDLE, HANDLE, LPSTACKFRAME, PVOID,
- PREAD_PROCESS_MEMORY_ROUTINE, PFUNCTION_TABLE_ACCESS_ROUTINE, PGET_MODULE_BASE_ROUTINE,
- PTRANSLATE_ADDRESS_ROUTINE );
+typedef BOOL (WINAPI *ENUMERATELOADEDMODULES64)( HANDLE, PENUMLOADED_MODULES_CALLBACK64, PVOID );
+typedef BOOL (WINAPI *STACKWALK64)( DWORD, HANDLE, HANDLE, LPSTACKFRAME64, PVOID,
+ PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64,
+ PTRANSLATE_ADDRESS_ROUTINE64 );
typedef BOOL (WINAPI *SYMFROMADDR)( HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO );
-typedef PVOID (WINAPI *SYMFUNCTIONTABLEACCESS)( HANDLE, DWORD );
-typedef DWORD (WINAPI *SYMGETMODULEBASE)( HANDLE, DWORD );
+typedef PVOID (WINAPI *SYMFUNCTIONTABLEACCESS64)( HANDLE, DWORD64 );
+typedef DWORD64 (WINAPI *SYMGETMODULEBASE64)( HANDLE, DWORD64 );
typedef HINSTANCE (WINAPI *SHELLEXECUTE)( HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, INT );
PRIVATE SETSYMOPTIONS pSymSetOptions;
-PRIVATE SYMGETMODULEINFO pSymGetModuleInfo;
+PRIVATE SYMGETMODULEINFO64 pSymGetModuleInfo64;
PRIVATE SYMINITIALIZE pSymInitialize;
PRIVATE SYMCLEANUP pSymCleanup;
-PRIVATE ENUMERATELOADEDMODULES pEnumerateLoadedModules;
-PRIVATE STACKWALK pStackWalk;
+PRIVATE ENUMERATELOADEDMODULES64 pEnumerateLoadedModules64;
+PRIVATE STACKWALK64 pStackWalk64;
PRIVATE SYMFROMADDR pSymFromAddr;
-PRIVATE SYMFUNCTIONTABLEACCESS pSymFunctionTableAccess;
-PRIVATE SYMGETMODULEBASE pSymGetModuleBase;
+PRIVATE SYMFUNCTIONTABLEACCESS64 pSymFunctionTableAccess64;
+PRIVATE SYMGETMODULEBASE64 pSymGetModuleBase64;
PRIVATE SHELLEXECUTE pShellExecute;
PRIVATE HANDLE processHandle, threadHandle;
@@ -1185,13 +1185,13 @@ PRIVATE FILE *crashReport;
PRIVATE CHAR moduleName[MAX_PATH];
PRIVATE BOOL CALLBACK EnumModulesCallback(
- PSTR ModuleName,
- ULONG ModuleBase,
+ PTSTR ModuleName,
+ DWORD64 ModuleBase,
ULONG ModuleSize,
PVOID UserContext )
{
- IMAGEHLP_MODULE moduleInfo;
- DWORD pc = ( DWORD )UserContext;
+ IMAGEHLP_MODULE64 moduleInfo;
+ DWORD64 pc = ( DWORD64 )UserContext;
BYTE buffer[4096];
PBYTE data;
UINT numBytes;
@@ -1213,7 +1213,7 @@ PRIVATE BOOL CALLBACK EnumModulesCallback(
symbols = "failed";
moduleInfo.SizeOfStruct = sizeof( moduleInfo );
- if( pSymGetModuleInfo( processHandle, ModuleBase, &moduleInfo ) ) {
+ if( pSymGetModuleInfo64( processHandle, ModuleBase, &moduleInfo ) ) {
ModuleName = moduleInfo.ModuleName;
switch( moduleInfo.SymType ) {
case SymCoff: symbols = "COFF"; break;
@@ -1224,7 +1224,7 @@ PRIVATE BOOL CALLBACK EnumModulesCallback(
}
}
- fprintf( crashReport, "%08x %08x %s (version %s, symbols %s) ",
+ fprintf( crashReport, "%p %p %s (version %s, symbols %s) ",
ModuleBase, ModuleBase + ModuleSize, ModuleName, version, symbols );
if( pc >= ModuleBase && pc < ModuleBase + ModuleSize ) {
strncpy( moduleName, ModuleName, sizeof( moduleName ) - 1 );
@@ -1238,19 +1238,19 @@ PRIVATE BOOL CALLBACK EnumModulesCallback(
}
PRIVATE DWORD Sys_ExceptionHandler( DWORD exceptionCode, LPEXCEPTION_POINTERS exceptionInfo ) {
- STACKFRAME stackFrame;
+ STACKFRAME64 stackFrame;
PCONTEXT context;
SYMBOL_INFO *symbol;
int count, ret, i, len;
DWORD64 offset;
BYTE buffer[sizeof( SYMBOL_INFO ) + 256 - 1];
- IMAGEHLP_MODULE moduleInfo;
+ IMAGEHLP_MODULE64 moduleInfo;
char path[MAX_PATH];
char execdir[MAX_PATH];
char *p;
HMODULE helpModule, shellModule;
SYSTEMTIME systemTime;
- static char *monthNames[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ static const char monthNames[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
OSVERSIONINFO vinfo;
@@ -1285,14 +1285,14 @@ PRIVATE DWORD Sys_ExceptionHandler( DWORD exceptionCode, LPEXCEPTION_POINTERS ex
} while( 0 )
GPA( SETSYMOPTIONS, SymSetOptions );
- GPA( SYMGETMODULEINFO, SymGetModuleInfo );
+ GPA( SYMGETMODULEINFO64, SymGetModuleInfo64 );
GPA( SYMCLEANUP, SymCleanup );
GPA( SYMINITIALIZE, SymInitialize );
- GPA( ENUMERATELOADEDMODULES, EnumerateLoadedModules );
- GPA( STACKWALK, StackWalk );
+ GPA( ENUMERATELOADEDMODULES64, EnumerateLoadedModules64 );
+ GPA( STACKWALK64, StackWalk64 );
GPA( SYMFROMADDR, SymFromAddr );
- GPA( SYMFUNCTIONTABLEACCESS, SymFunctionTableAccess );
- GPA( SYMGETMODULEBASE, SymGetModuleBase );
+ GPA( SYMFUNCTIONTABLEACCESS64, SymFunctionTableAccess64 );
+ GPA( SYMGETMODULEBASE64, SymGetModuleBase64 );
pSymSetOptions( SYMOPT_LOAD_ANYTHING|SYMOPT_DEBUG|SYMOPT_FAIL_CRITICAL_ERRORS );
processHandle = GetCurrentProcess();
@@ -1344,45 +1344,76 @@ PRIVATE DWORD Sys_ExceptionHandler( DWORD exceptionCode, LPEXCEPTION_POINTERS ex
context = exceptionInfo->ContextRecord;
fprintf( crashReport, "\nLoaded modules:\n" );
- pEnumerateLoadedModules( processHandle, EnumModulesCallback, ( PVOID )context->Eip );
+ pEnumerateLoadedModules64( processHandle, EnumModulesCallback,
+#ifdef _WIN64
+ ( PVOID )context->Rip
+#else
+ ( PVOID )context->Eip
+#endif
+ );
fprintf( crashReport, "\nException information:\n" );
fprintf( crashReport, "Code: %08x\n", exceptionCode );
- fprintf( crashReport, "Address: %08x (%s)\n",
- context->Eip, moduleName );
+ fprintf( crashReport, "Address: %p (%s)\n",
+#ifdef _WIN64
+ context->Rip,
+#else
+ context->Eip,
+#endif
+ moduleName );
fprintf( crashReport, "\nThread context:\n" );
- fprintf( crashReport, "EIP: %08x EBP: %08x ESP: %08x\n",
+#ifdef _WIN64
+ fprintf( crashReport, "RIP: %p RBP: %p RSP: %p\n",
+ context->Rip, context->Rbp, context->Rsp );
+ fprintf( crashReport, "RAX: %p RBX: %p RCX: %p\n",
+ context->Rax, context->Rbx, context->Rcx );
+ fprintf( crashReport, "RDX: %p RSI: %p RDI: %p\n",
+ context->Rdx, context->Rsi, context->Rdi );
+#else
+ fprintf( crashReport, "EIP: %p EBP: %p ESP: %p\n",
context->Eip, context->Ebp, context->Esp );
- fprintf( crashReport, "EAX: %08x EBX: %08x ECX: %08x\n",
+ fprintf( crashReport, "EAX: %p EBX: %p ECX: %p\n",
context->Eax, context->Ebx, context->Ecx );
- fprintf( crashReport, "EDX: %08x ESI: %08x EDI: %08x\n",
+ fprintf( crashReport, "EDX: %p ESI: %p EDI: %p\n",
context->Edx, context->Esi, context->Edi );
+#endif
memset( &stackFrame, 0, sizeof( stackFrame ) );
+#ifdef _WIN64
+ stackFrame.AddrPC.Offset = context->Rip;
+ stackFrame.AddrFrame.Offset = context->Rbp;
+ stackFrame.AddrStack.Offset = context->Rsp;
+#else
stackFrame.AddrPC.Offset = context->Eip;
- stackFrame.AddrPC.Mode = AddrModeFlat;
stackFrame.AddrFrame.Offset = context->Ebp;
- stackFrame.AddrFrame.Mode = AddrModeFlat;
stackFrame.AddrStack.Offset = context->Esp;
+#endif
+ stackFrame.AddrPC.Mode = AddrModeFlat;
+ stackFrame.AddrFrame.Mode = AddrModeFlat;
stackFrame.AddrStack.Mode = AddrModeFlat;
fprintf( crashReport, "\nStack trace:\n" );
count = 0;
symbol = ( SYMBOL_INFO * )buffer;
- symbol->SizeOfStruct = sizeof( *symbol );
+ symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
symbol->MaxNameLen = 256;
- while( pStackWalk( IMAGE_FILE_MACHINE_I386,
+ while( pStackWalk64(
+#ifdef _WIN64
+ IMAGE_FILE_MACHINE_AMD64,
+#else
+ IMAGE_FILE_MACHINE_I386,
+#endif
processHandle,
threadHandle,
&stackFrame,
context,
NULL,
- pSymFunctionTableAccess,
- pSymGetModuleBase,
+ pSymFunctionTableAccess64,
+ pSymGetModuleBase64,
NULL ) )
{
- fprintf( crashReport, "%d: %08x %08x %08x %08x ",
+ fprintf( crashReport, "%d: %p %p %p %p ",
count,
stackFrame.Params[0],
stackFrame.Params[1],
@@ -1390,7 +1421,7 @@ PRIVATE DWORD Sys_ExceptionHandler( DWORD exceptionCode, LPEXCEPTION_POINTERS ex
stackFrame.Params[3] );
moduleInfo.SizeOfStruct = sizeof( moduleInfo );
- if( pSymGetModuleInfo( processHandle, stackFrame.AddrPC.Offset, &moduleInfo ) ) {
+ if( pSymGetModuleInfo64( processHandle, stackFrame.AddrPC.Offset, &moduleInfo ) ) {
if( moduleInfo.SymType != SymNone && moduleInfo.SymType != SymExport &&
pSymFromAddr( processHandle, stackFrame.AddrPC.Offset, &offset, symbol ) )
{
diff --git a/source/ui_addressbook.c b/source/ui_addressbook.c
index 511a6c5..641331a 100644
--- a/source/ui_addressbook.c
+++ b/source/ui_addressbook.c
@@ -74,7 +74,7 @@ static void AddressBook_MenuInit( void ) {
m_addressBook.fields[i].generic.type = MTYPE_FIELD;
- IF_InitText( &m_addressBook.fields[i].field, 30, 60,
+ IF_Init( &m_addressBook.fields[i].field, 30, 60,
cvar.VariableString( buffer ) );
Menu_AddItem( &m_addressBook.menu, &m_addressBook.fields[i] );
diff --git a/source/ui_atoms.c b/source/ui_atoms.c
index 14673fc..45976ca 100644
--- a/source/ui_atoms.c
+++ b/source/ui_atoms.c
@@ -250,9 +250,10 @@ UI_FormatColumns
void *UI_FormatColumns( int extrasize, ... ) {
va_list argptr;
char *buffer, *p;
- int i, j, total = 0;
+ int i, j;
+ size_t total = 0;
char *strings[MAX_COLUMNS];
- int lengths[MAX_COLUMNS];
+ size_t lengths[MAX_COLUMNS];
va_start( argptr, extrasize );
for( i = 0; i < MAX_COLUMNS; i++ ) {
diff --git a/source/ui_demos.c b/source/ui_demos.c
index f9b2065..e6905f9 100644
--- a/source/ui_demos.c
+++ b/source/ui_demos.c
@@ -87,9 +87,9 @@ static void Demos_BuildName( fsFileInfo_t *info, char **cache ) {
if( info->size >= 1000000 ) {
sprintf( buffer, "%2.1fM", ( float )info->size / 1000000 );
} else if( info->size >= 1000 ) {
- sprintf( buffer, "%3dK", info->size / 1000 );
+ sprintf( buffer, "%3"PRIz"K", info->size / 1000 );
} else {
- sprintf( buffer, "%3db", info->size );
+ sprintf( buffer, "%3"PRIz"b", info->size );
}
e = UI_FormatColumns( DEMO_EXTRASIZE,
@@ -114,7 +114,8 @@ static void Demos_BuildDir( const char *name, int type ) {
static char *Demos_LoadCache( void **list ) {
char buffer[MAX_OSPATH], *cache;
- int i, len;
+ int i;
+ size_t len;
uint8_t hash[16];
Q_concat( buffer, sizeof( buffer ), uis.m_demos_browse, "/" COM_DEMOCACHE_NAME, NULL );
@@ -182,7 +183,7 @@ static void Demos_WriteCache( void ) {
static void Demos_CalcHash( void **list ) {
struct mdfour md;
fsFileInfo_t *info;
- int len;
+ size_t len;
mdfour_begin( &md );
while( *list ) {
@@ -315,7 +316,7 @@ static void Demos_LeaveDirectory( void ) {
static int Demos_Action( void ) {
// char buffer[MAX_OSPTH];
- int len, baselen;
+ size_t len, baselen;
demoEntry_t *e = m_demos.list.items[m_demos.list.curvalue];
switch( e->type ) {
diff --git a/source/ui_network.c b/source/ui_network.c
index 24f329f..cf64f06 100644
--- a/source/ui_network.c
+++ b/source/ui_network.c
@@ -72,9 +72,9 @@ static const int connectionValues[][2] = {
static const int numConnectionValues = sizeof( connectionValues ) / sizeof( connectionValues[0] );
static void SetInitialConnectionParams( void ) {
- IF_InitText( &m_network.rate.field, 6, 6, cvar.VariableString( "rate" ) );
- IF_InitText( &m_network.maxpackets.field, 6, 6, cvar.VariableString( "cl_maxpackets" ) );
- IF_InitText( &m_network.maxfps.field, 6, 6, cvar.VariableString( "cl_maxfps" ) );
+ IF_Init( &m_network.rate.field, 6, 6, cvar.VariableString( "rate" ) );
+ IF_Init( &m_network.maxpackets.field, 6, 6, cvar.VariableString( "cl_maxpackets" ) );
+ IF_Init( &m_network.maxfps.field, 6, 6, cvar.VariableString( "cl_maxfps" ) );
}
static void ConnectionCallback( void ) {
diff --git a/source/ui_playerconfig.c b/source/ui_playerconfig.c
index 5fc0c67..a7e9f97 100644
--- a/source/ui_playerconfig.c
+++ b/source/ui_playerconfig.c
@@ -272,7 +272,7 @@ qboolean PlayerConfig_MenuInit( void ) {
m_playerConfig.nameField.generic.type = MTYPE_FIELD;
m_playerConfig.nameField.generic.flags = QMF_HASFOCUS;
m_playerConfig.nameField.generic.name = "name";
- IF_InitText( &m_playerConfig.nameField.field, 16, 16,
+ IF_Init( &m_playerConfig.nameField.field, 16, 16,
cvar.VariableString( "name" ) );
m_playerConfig.modelBox.generic.type = MTYPE_SPINCONTROL;
diff --git a/source/ui_playermodels.c b/source/ui_playermodels.c
index 83f22a7..91250a7 100644
--- a/source/ui_playermodels.c
+++ b/source/ui_playermodels.c
@@ -140,7 +140,7 @@ void PlayerModel_Load( void ) {
// verify the existence of tris.md2
Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], "/tris.md2", NULL );
- if( fs.LoadFile( scratch, NULL ) < 1 ) {
+ if( fs.LoadFile( scratch, NULL ) == INVALID_LENGTH ) {
continue;
}