engine: avoid constants in Q_strncpy third argument, where possible

This commit is contained in:
Alibek Omarov 2024-05-06 14:27:26 +03:00
parent 5120657386
commit a6c2cfe89b
16 changed files with 32 additions and 32 deletions

View file

@ -192,7 +192,7 @@ void CL_RegisterEvent( int lastnum, const char *szEvName, pfnEventHook func )
ev = clgame.events[lastnum]; ev = clgame.events[lastnum];
// NOTE: ev->index will be set later // 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; ev->func = func;
} }

View file

@ -194,7 +194,7 @@ static void CL_LegacyPrecacheModel( sizebuf_t *msg )
if( modelIndex < 0 || modelIndex >= MAX_MODELS ) if( modelIndex < 0 || modelIndex >= MAX_MODELS )
Host_Error( "CL_PrecacheModel: bad modelindex %i\n", modelIndex ); 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] )); //Q_strncpy( cl.model_precache[modelIndex], BF_ReadString( msg ), sizeof( cl.model_precache[0] ));
// when we loading map all resources is precached sequentially // 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++ ) for( i = 0; i < reslist.rescount; i++ )
{ {
reslist.restype[i] = MSG_ReadWord( msg ); 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() ) if( CL_IsPlaybackDemo() )

View file

@ -853,7 +853,7 @@ static void CL_SetupPMove( playermove_t *pmove, const local_state_t *from, const
VectorCopy( cd->vuser4, pmove->vuser4 ); VectorCopy( cd->vuser4, pmove->vuser4 );
pmove->cmd = *ucmd; // copy current cmds 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 ) static const void CL_FinishPMove( const playermove_t *pmove, local_state_t *to )

View file

@ -211,7 +211,7 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg )
clgame.maxEntities = GI->max_edicts; clgame.maxEntities = GI->max_edicts;
clgame.maxEntities = bound( 600, clgame.maxEntities, MAX_EDICTS ); clgame.maxEntities = bound( 600, clgame.maxEntities, MAX_EDICTS );
clgame.maxModels = MAX_MODELS; 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 // Re-init hud video, especially if we changed game directories
clgame.dllFuncs.pfnVidInit(); clgame.dllFuncs.pfnVidInit();

View file

@ -1138,7 +1138,7 @@ Field_Set
static void Field_Set( field_t *f, const char *string ) static void Field_Set( field_t *f, const char *string )
{ {
f->scroll = 0; f->scroll = 0;
f->cursor = Q_strncpy( f->buffer, string, MAX_STRING ); f->cursor = Q_strncpy( f->buffer, string, sizeof( f->buffer ));
} }
/* /*

View file

@ -380,7 +380,7 @@ S_InitSounds
void S_InitSounds( void ) void S_InitSounds( void )
{ {
// create unused 0-entry // 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->hashValue = COM_HashKey( s_knownSfx->name, MAX_SFX_HASH );
s_knownSfx->hashNext = s_sfxHashList[s_knownSfx->hashValue]; s_knownSfx->hashNext = s_sfxHashList[s_knownSfx->hashValue];
s_sfxHashList[s_knownSfx->hashValue] = s_knownSfx; s_sfxHashList[s_knownSfx->hashValue] = s_knownSfx;

View file

@ -1015,7 +1015,7 @@ static void Cmd_ExecuteStringWithPrivilegeCheck( const char *text, qboolean isPr
*ptoken++ = *text++; *ptoken++ = *text++;
*ptoken = 0; *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; pcmd = command + len;
if( !*text ) break; if( !*text ) break;

View file

@ -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 ); t = FS_Search( va( "%s%s*.*", DEFAULT_SOUNDPATH, s ), true, false );
if( !t ) return 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 ); COM_StripExtension( matchbuf );
if( completedname && length ) if( completedname && length )
Q_strncpy( completedname, matchbuf, 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" )) if( Q_stricmp( ext, "wav" ) && Q_stricmp( ext, "mp3" ))
continue; 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 ); COM_StripExtension( matchbuf );
Con_Printf( "%16s\n", matchbuf ); Con_Printf( "%16s\n", matchbuf );
numsounds++; numsounds++;
@ -764,14 +764,14 @@ static qboolean Cmd_GetGamesList( const char *s, char *completedname, int length
} }
if( !numgamedirs ) return false; if( !numgamedirs ) return false;
Q_strncpy( matchbuf, gamedirs[0], MAX_STRING ); Q_strncpy( matchbuf, gamedirs[0], sizeof( matchbuf ));
if( completedname && length ) if( completedname && length )
Q_strncpy( completedname, matchbuf, length ); Q_strncpy( completedname, matchbuf, length );
if( numgamedirs == 1 ) return true; if( numgamedirs == 1 ) return true;
for( i = 0; i < numgamedirs; i++ ) 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 ); Con_Printf( "%16s\n", matchbuf );
} }
@ -825,14 +825,14 @@ static qboolean Cmd_GetCDList( const char *s, char *completedname, int length )
} }
if( !numcdcommands ) return false; if( !numcdcommands ) return false;
Q_strncpy( matchbuf, cdcommands[0], MAX_STRING ); Q_strncpy( matchbuf, cdcommands[0], sizeof( matchbuf ));
if( completedname && length ) if( completedname && length )
Q_strncpy( completedname, matchbuf, length ); Q_strncpy( completedname, matchbuf, length );
if( numcdcommands == 1 ) return true; if( numcdcommands == 1 ) return true;
for( i = 0; i < numcdcommands; i++ ) 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 ); Con_Printf( "%16s\n", matchbuf );
} }
@ -901,12 +901,10 @@ static qboolean Cmd_CheckMapsList_R( qboolean fRefresh, qboolean onlyingamedir )
if( f ) if( f )
{ {
qboolean have_spawnpoints = false; qboolean have_spawnpoints = false;
dheader_t *header;
dlump_t entities; dlump_t entities;
memset( buf, 0, MAX_SYSPATH ); memset( buf, 0, MAX_SYSPATH );
FS_Read( f, buf, MAX_SYSPATH ); FS_Read( f, buf, MAX_SYSPATH );
header = (dheader_t *)buf;
// check all the lumps and some other errors // check all the lumps and some other errors
if( !Mod_TestBmodelLumps( f, t->filenames[i], buf, true, &entities )) 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]; char token[MAX_TOKEN];
qboolean worldspawn = true; qboolean worldspawn = true;
Q_strncpy( message, "No Title", MAX_STRING ); Q_strncpy( message, "No Title", sizeof( message ));
pfile = ents; pfile = ents;
while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL ) while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL )

View file

@ -865,7 +865,7 @@ void GAME_EXPORT Host_Error( const char *error, ... )
} }
recursive = true; recursive = true;
Q_strncpy( hosterror2, hosterror1, MAX_SYSPATH ); Q_strncpy( hosterror2, hosterror1, sizeof( hosterror2 ));
host.errorframe = host.framecount; // to avoid multply calls per frame host.errorframe = host.framecount; // to avoid multply calls per frame
Q_snprintf( host.finalmsg, sizeof( host.finalmsg ), "Server crashed: %s", hosterror1 ); Q_snprintf( host.finalmsg, sizeof( host.finalmsg ), "Server crashed: %s", hosterror1 );

View file

@ -262,7 +262,7 @@ static void NET_AddMaster( const char *addr, qboolean save )
} }
master = Mem_Malloc( host.mempool, sizeof( master_t ) ); 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->sent = false;
master->save = save; master->save = save;
master->next = NULL; master->next = NULL;

View file

@ -1823,8 +1823,8 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod )
{ {
char *pszWadFile; char *pszWadFile;
Q_strncpy( wadstring, token, MAX_TOKEN - 2 ); Q_strncpy( wadstring, token, sizeof( wadstring ) - 2 );
wadstring[MAX_TOKEN - 2] = 0; wadstring[sizeof( wadstring ) - 2] = 0;
if( !Q_strchr( wadstring, ';' )) if( !Q_strchr( wadstring, ';' ))
Q_strncat( wadstring, ";", sizeof( wadstring )); Q_strncat( wadstring, ";", sizeof( wadstring ));

View file

@ -175,11 +175,13 @@ void Evdev_Autodetect_f( void )
if( evdev.devices >= MAX_EVDEV_DEVICES ) if( evdev.devices >= MAX_EVDEV_DEVICES )
continue; 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++ ) 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; goto next;
}
if( Q_strncmp( entry->d_name, "event", 5 ) ) if( Q_strncmp( entry->d_name, "event", 5 ) )
continue; continue;
@ -220,7 +222,7 @@ void Evdev_Autodetect_f( void )
} }
goto close; goto close;
open: 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; evdev.fds[evdev.devices++] = fd;
Con_Printf( "Opened device %s\n", path ); Con_Printf( "Opened device %s\n", path );
#if XASH_INPUT == INPUT_EVDEV #if XASH_INPUT == INPUT_EVDEV
@ -260,7 +262,7 @@ void Evdev_OpenDevice ( const char *path )
for( i = 0; i < evdev.devices; i++ ) 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 ); Con_Printf( "device %s already open!\n", path );
return; return;
@ -275,7 +277,7 @@ void Evdev_OpenDevice ( const char *path )
} }
Con_Printf( "Input device #%d: %s opened sucessfully\n", evdev.devices, path ); Con_Printf( "Input device #%d: %s opened sucessfully\n", evdev.devices, path );
evdev.fds[evdev.devices] = ret; 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 XASH_INPUT == INPUT_EVDEV
if( Sys_CheckParm( "-grab" ) ) if( Sys_CheckParm( "-grab" ) )
@ -309,7 +311,7 @@ void Evdev_CloseDevice_f ( void )
if( Q_isdigit( arg ) ) if( Q_isdigit( arg ) )
i = Q_atoi( arg ); i = Q_atoi( arg );
else for( i = 0; i < evdev.devices; i++ ) 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; break;
if( i >= evdev.devices ) if( i >= evdev.devices )
@ -324,7 +326,7 @@ void Evdev_CloseDevice_f ( void )
for( ; i < evdev.devices; i++ ) 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]; evdev.fds[i] = evdev.fds[i+1];
} }
} }

View file

@ -417,7 +417,7 @@ static void SV_ConnectClient( netadr_t from )
newcl->userid = g_userid++; // create unique userid newcl->userid = g_userid++; // create unique userid
newcl->state = cs_connected; newcl->state = cs_connected;
newcl->extensions = extensions & (NET_EXT_SPLITSIZE); 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) // reset viewentities (from previous level)
memset( newcl->viewentity, 0, sizeof( newcl->viewentity )); memset( newcl->viewentity, 0, sizeof( newcl->viewentity ));

View file

@ -690,7 +690,7 @@ static void SV_ConSay_f( void )
} }
p = Cmd_Args(); p = Cmd_Args();
Q_strncpy( text, *p == '"' ? p + 1 : p, MAX_SYSPATH ); Q_strncpy( text, *p == '"' ? p + 1 : p, sizeof( text ));
if( *p == '"' ) if( *p == '"' )
{ {

View file

@ -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->cmd = *ucmd; // setup current cmds
pmove->runfuncs = true; pmove->runfuncs = true;
Q_strncpy( pmove->physinfo, physinfo, MAX_INFO_STRING ); Q_strncpy( pmove->physinfo, physinfo, sizeof( pmove->physinfo ));
// setup physents // setup physents
pmove->numvisent = 0; pmove->numvisent = 0;

View file

@ -652,7 +652,7 @@ static void DirectoryCopy( const char *pPath, file_t *pFile )
fileSize = FS_FileLength( pCopy ); fileSize = FS_FileLength( pCopy );
memset( szName, 0, sizeof( szName )); // clearing the string to prevent garbage in output file 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, szName, MAX_OSPATH );
FS_Write( pFile, &fileSize, sizeof( int )); FS_Write( pFile, &fileSize, sizeof( int ));
FS_FileCopy( pFile, pCopy, fileSize ); FS_FileCopy( pFile, pCopy, fileSize );