diff --git a/engine/client/cl_events.c b/engine/client/cl_events.c index 2b16b310..ed66a5f8 100644 --- a/engine/client/cl_events.c +++ b/engine/client/cl_events.c @@ -192,7 +192,7 @@ void CL_RegisterEvent( int lastnum, const char *szEvName, pfnEventHook func ) ev = clgame.events[lastnum]; // NOTE: ev->index will be set later - Q_strncpy( ev->name, szEvName, MAX_QPATH ); + Q_strncpy( ev->name, szEvName, sizeof( ev->name )); ev->func = func; } diff --git a/engine/client/cl_parse_48.c b/engine/client/cl_parse_48.c index 61fa3071..54ffbe8f 100644 --- a/engine/client/cl_parse_48.c +++ b/engine/client/cl_parse_48.c @@ -194,7 +194,7 @@ static void CL_LegacyPrecacheModel( sizebuf_t *msg ) if( modelIndex < 0 || modelIndex >= MAX_MODELS ) Host_Error( "CL_PrecacheModel: bad modelindex %i\n", modelIndex ); - Q_strncpy( model, MSG_ReadString( msg ), MAX_STRING ); + Q_strncpy( model, MSG_ReadString( msg ), sizeof( model )); //Q_strncpy( cl.model_precache[modelIndex], BF_ReadString( msg ), sizeof( cl.model_precache[0] )); // when we loading map all resources is precached sequentially @@ -261,7 +261,7 @@ static void CL_LegacyParseResourceList( sizebuf_t *msg ) for( i = 0; i < reslist.rescount; i++ ) { reslist.restype[i] = MSG_ReadWord( msg ); - Q_strncpy( reslist.resnames[i], MSG_ReadString( msg ), MAX_QPATH ); + Q_strncpy( reslist.resnames[i], MSG_ReadString( msg ), sizeof( reslist.resnames[i] )); } if( CL_IsPlaybackDemo() ) diff --git a/engine/client/cl_pmove.c b/engine/client/cl_pmove.c index 1991da37..e84b648f 100644 --- a/engine/client/cl_pmove.c +++ b/engine/client/cl_pmove.c @@ -853,7 +853,7 @@ static void CL_SetupPMove( playermove_t *pmove, const local_state_t *from, const VectorCopy( cd->vuser4, pmove->vuser4 ); pmove->cmd = *ucmd; // copy current cmds - Q_strncpy( pmove->physinfo, cls.physinfo, MAX_INFO_STRING ); + Q_strncpy( pmove->physinfo, cls.physinfo, sizeof( pmove->physinfo )); } static const void CL_FinishPMove( const playermove_t *pmove, local_state_t *to ) diff --git a/engine/client/cl_qparse.c b/engine/client/cl_qparse.c index 49575198..f65522eb 100644 --- a/engine/client/cl_qparse.c +++ b/engine/client/cl_qparse.c @@ -211,7 +211,7 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg ) clgame.maxEntities = GI->max_edicts; clgame.maxEntities = bound( 600, clgame.maxEntities, MAX_EDICTS ); clgame.maxModels = MAX_MODELS; - Q_strncpy( clgame.maptitle, MSG_ReadString( msg ), MAX_STRING ); + Q_strncpy( clgame.maptitle, MSG_ReadString( msg ), sizeof( clgame.maptitle )); // Re-init hud video, especially if we changed game directories clgame.dllFuncs.pfnVidInit(); diff --git a/engine/client/console.c b/engine/client/console.c index 13ab4632..6fd6312a 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -1138,7 +1138,7 @@ Field_Set static void Field_Set( field_t *f, const char *string ) { f->scroll = 0; - f->cursor = Q_strncpy( f->buffer, string, MAX_STRING ); + f->cursor = Q_strncpy( f->buffer, string, sizeof( f->buffer )); } /* diff --git a/engine/client/s_load.c b/engine/client/s_load.c index ce4dcb86..4db2e9b4 100644 --- a/engine/client/s_load.c +++ b/engine/client/s_load.c @@ -380,7 +380,7 @@ S_InitSounds void S_InitSounds( void ) { // create unused 0-entry - Q_strncpy( s_knownSfx->name, "*default", MAX_QPATH ); + Q_strncpy( s_knownSfx->name, "*default", sizeof( s_knownSfx->name )); s_knownSfx->hashValue = COM_HashKey( s_knownSfx->name, MAX_SFX_HASH ); s_knownSfx->hashNext = s_sfxHashList[s_knownSfx->hashValue]; s_sfxHashList[s_knownSfx->hashValue] = s_knownSfx; diff --git a/engine/common/cmd.c b/engine/common/cmd.c index 21e2a16b..38fd1b92 100644 --- a/engine/common/cmd.c +++ b/engine/common/cmd.c @@ -1015,7 +1015,7 @@ static void Cmd_ExecuteStringWithPrivilegeCheck( const char *text, qboolean isPr *ptoken++ = *text++; *ptoken = 0; - len += Q_strncpy( pcmd, Cvar_VariableString( token ), MAX_CMD_LINE - len ); + len += Q_strncpy( pcmd, Cvar_VariableString( token ), sizeof( token ) - len ); pcmd = command + len; if( !*text ) break; diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index 16f2e014..6bad2d52 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -465,7 +465,7 @@ static qboolean Cmd_GetSoundList( const char *s, char *completedname, int length t = FS_Search( va( "%s%s*.*", DEFAULT_SOUNDPATH, s ), true, false ); if( !t ) return false; - Q_strncpy( matchbuf, t->filenames[0] + sizeof( DEFAULT_SOUNDPATH ) - 1, MAX_STRING ); + Q_strncpy( matchbuf, t->filenames[0] + sizeof( DEFAULT_SOUNDPATH ) - 1, sizeof( matchbuf )); COM_StripExtension( matchbuf ); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); @@ -478,7 +478,7 @@ static qboolean Cmd_GetSoundList( const char *s, char *completedname, int length if( Q_stricmp( ext, "wav" ) && Q_stricmp( ext, "mp3" )) continue; - Q_strncpy( matchbuf, t->filenames[i] + sizeof( DEFAULT_SOUNDPATH ) - 1, MAX_STRING ); + Q_strncpy( matchbuf, t->filenames[i] + sizeof( DEFAULT_SOUNDPATH ) - 1, sizeof( matchbuf )); COM_StripExtension( matchbuf ); Con_Printf( "%16s\n", matchbuf ); numsounds++; @@ -764,14 +764,14 @@ static qboolean Cmd_GetGamesList( const char *s, char *completedname, int length } if( !numgamedirs ) return false; - Q_strncpy( matchbuf, gamedirs[0], MAX_STRING ); + Q_strncpy( matchbuf, gamedirs[0], sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( numgamedirs == 1 ) return true; for( i = 0; i < numgamedirs; i++ ) { - Q_strncpy( matchbuf, gamedirs[i], MAX_STRING ); + Q_strncpy( matchbuf, gamedirs[i], sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); } @@ -825,14 +825,14 @@ static qboolean Cmd_GetCDList( const char *s, char *completedname, int length ) } if( !numcdcommands ) return false; - Q_strncpy( matchbuf, cdcommands[0], MAX_STRING ); + Q_strncpy( matchbuf, cdcommands[0], sizeof( matchbuf )); if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); if( numcdcommands == 1 ) return true; for( i = 0; i < numcdcommands; i++ ) { - Q_strncpy( matchbuf, cdcommands[i], MAX_STRING ); + Q_strncpy( matchbuf, cdcommands[i], sizeof( matchbuf )); Con_Printf( "%16s\n", matchbuf ); } @@ -901,12 +901,10 @@ static qboolean Cmd_CheckMapsList_R( qboolean fRefresh, qboolean onlyingamedir ) if( f ) { qboolean have_spawnpoints = false; - dheader_t *header; dlump_t entities; memset( buf, 0, MAX_SYSPATH ); FS_Read( f, buf, MAX_SYSPATH ); - header = (dheader_t *)buf; // check all the lumps and some other errors if( !Mod_TestBmodelLumps( f, t->filenames[i], buf, true, &entities )) @@ -937,7 +935,7 @@ static qboolean Cmd_CheckMapsList_R( qboolean fRefresh, qboolean onlyingamedir ) char token[MAX_TOKEN]; qboolean worldspawn = true; - Q_strncpy( message, "No Title", MAX_STRING ); + Q_strncpy( message, "No Title", sizeof( message )); pfile = ents; while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL ) diff --git a/engine/common/host.c b/engine/common/host.c index a9a4e7d1..78239bb2 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -865,7 +865,7 @@ void GAME_EXPORT Host_Error( const char *error, ... ) } recursive = true; - Q_strncpy( hosterror2, hosterror1, MAX_SYSPATH ); + Q_strncpy( hosterror2, hosterror1, sizeof( hosterror2 )); host.errorframe = host.framecount; // to avoid multply calls per frame Q_snprintf( host.finalmsg, sizeof( host.finalmsg ), "Server crashed: %s", hosterror1 ); diff --git a/engine/common/masterlist.c b/engine/common/masterlist.c index fb420330..8df6cc51 100644 --- a/engine/common/masterlist.c +++ b/engine/common/masterlist.c @@ -262,7 +262,7 @@ static void NET_AddMaster( const char *addr, qboolean save ) } master = Mem_Malloc( host.mempool, sizeof( master_t ) ); - Q_strncpy( master->address, addr, MAX_STRING ); + Q_strncpy( master->address, addr, sizeof( master->address )); master->sent = false; master->save = save; master->next = NULL; diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 229a972a..1de37c32 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -1823,8 +1823,8 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod ) { char *pszWadFile; - Q_strncpy( wadstring, token, MAX_TOKEN - 2 ); - wadstring[MAX_TOKEN - 2] = 0; + Q_strncpy( wadstring, token, sizeof( wadstring ) - 2 ); + wadstring[sizeof( wadstring ) - 2] = 0; if( !Q_strchr( wadstring, ';' )) Q_strncat( wadstring, ";", sizeof( wadstring )); diff --git a/engine/platform/linux/in_evdev.c b/engine/platform/linux/in_evdev.c index 2c6e758c..ecccce6b 100644 --- a/engine/platform/linux/in_evdev.c +++ b/engine/platform/linux/in_evdev.c @@ -175,11 +175,13 @@ void Evdev_Autodetect_f( void ) if( evdev.devices >= MAX_EVDEV_DEVICES ) continue; - Q_snprintf( path, MAX_STRING, "/dev/input/%s", entry->d_name ); + Q_snprintf( path, sizeof( path ), "/dev/input/%s", entry->d_name ); for( i = 0; i < evdev.devices; i++ ) - if( !Q_strncmp( evdev.paths[i], path, MAX_STRING ) ) + { + if( !Q_strncmp( evdev.paths[i], path, sizeof( evdev.paths[i] )) goto next; + } if( Q_strncmp( entry->d_name, "event", 5 ) ) continue; @@ -220,7 +222,7 @@ void Evdev_Autodetect_f( void ) } goto close; open: - Q_strncpy( evdev.paths[evdev.devices], path, MAX_STRING ); + Q_strncpy( evdev.paths[evdev.devices], path, sizeof( evdev.paths[0] )); evdev.fds[evdev.devices++] = fd; Con_Printf( "Opened device %s\n", path ); #if XASH_INPUT == INPUT_EVDEV @@ -260,7 +262,7 @@ void Evdev_OpenDevice ( const char *path ) for( i = 0; i < evdev.devices; i++ ) { - if( !Q_strncmp( evdev.paths[i], path, MAX_STRING ) ) + if( !Q_strncmp( evdev.paths[i], path, sizeof( evdev.paths[i] ))) { Con_Printf( "device %s already open!\n", path ); return; @@ -275,7 +277,7 @@ void Evdev_OpenDevice ( const char *path ) } Con_Printf( "Input device #%d: %s opened sucessfully\n", evdev.devices, path ); evdev.fds[evdev.devices] = ret; - Q_strncpy( evdev.paths[evdev.devices++], path, MAX_STRING ); + Q_strncpy( evdev.paths[evdev.devices++], path, sizeof( evdev.paths[0] )); #if XASH_INPUT == INPUT_EVDEV if( Sys_CheckParm( "-grab" ) ) @@ -309,7 +311,7 @@ void Evdev_CloseDevice_f ( void ) if( Q_isdigit( arg ) ) i = Q_atoi( arg ); else for( i = 0; i < evdev.devices; i++ ) - if( !Q_strncmp( evdev.paths[i], arg, MAX_STRING ) ) + if( !Q_strncmp( evdev.paths[i], arg, sizeof( evdev.paths[i] ))) break; if( i >= evdev.devices ) @@ -324,7 +326,7 @@ void Evdev_CloseDevice_f ( void ) for( ; i < evdev.devices; i++ ) { - Q_strncpy( evdev.paths[i], evdev.paths[i+1], MAX_STRING ); + Q_strncpy( evdev.paths[i], evdev.paths[i+1], sizeof( evdev.paths[i] )); evdev.fds[i] = evdev.fds[i+1]; } } diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index 7245df4d..65bab913 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -417,7 +417,7 @@ static void SV_ConnectClient( netadr_t from ) newcl->userid = g_userid++; // create unique userid newcl->state = cs_connected; newcl->extensions = extensions & (NET_EXT_SPLITSIZE); - Q_strncpy( newcl->useragent, protinfo, MAX_INFO_STRING ); + Q_strncpy( newcl->useragent, protinfo, sizeof( newcl->useragent )); // reset viewentities (from previous level) memset( newcl->viewentity, 0, sizeof( newcl->viewentity )); diff --git a/engine/server/sv_cmds.c b/engine/server/sv_cmds.c index be667e7b..b005214a 100644 --- a/engine/server/sv_cmds.c +++ b/engine/server/sv_cmds.c @@ -690,7 +690,7 @@ static void SV_ConSay_f( void ) } p = Cmd_Args(); - Q_strncpy( text, *p == '"' ? p + 1 : p, MAX_SYSPATH ); + Q_strncpy( text, *p == '"' ? p + 1 : p, sizeof( text )); if( *p == '"' ) { diff --git a/engine/server/sv_pmove.c b/engine/server/sv_pmove.c index c47c74fd..1671c64d 100644 --- a/engine/server/sv_pmove.c +++ b/engine/server/sv_pmove.c @@ -590,7 +590,7 @@ static void SV_SetupPMove( playermove_t *pmove, sv_client_t *cl, usercmd_t *ucmd pmove->cmd = *ucmd; // setup current cmds pmove->runfuncs = true; - Q_strncpy( pmove->physinfo, physinfo, MAX_INFO_STRING ); + Q_strncpy( pmove->physinfo, physinfo, sizeof( pmove->physinfo )); // setup physents pmove->numvisent = 0; diff --git a/engine/server/sv_save.c b/engine/server/sv_save.c index b17e2776..473c9f51 100644 --- a/engine/server/sv_save.c +++ b/engine/server/sv_save.c @@ -652,7 +652,7 @@ static void DirectoryCopy( const char *pPath, file_t *pFile ) fileSize = FS_FileLength( pCopy ); memset( szName, 0, sizeof( szName )); // clearing the string to prevent garbage in output file - Q_strncpy( szName, COM_FileWithoutPath( t->filenames[i] ), MAX_OSPATH ); + Q_strncpy( szName, COM_FileWithoutPath( t->filenames[i] ), sizeof( szName )); FS_Write( pFile, szName, MAX_OSPATH ); FS_Write( pFile, &fileSize, sizeof( int )); FS_FileCopy( pFile, pCopy, fileSize );