Use idStr::Copynz() instead of strncpy()

to guarantee \0-termination
(only the applicable parts of that dhewm3 commit)
This commit is contained in:
Daniel Gibson 2022-05-17 03:23:12 +02:00
parent 37cdb06dce
commit 9cc5bb2352
5 changed files with 7 additions and 7 deletions

View file

@ -2639,7 +2639,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) {
// see if a target_sessionCommand has forced a changelevel
if ( sessionCommand.Length() ) {
strncpy( ret.sessionCommand, sessionCommand, sizeof( ret.sessionCommand ) );
idStr::Copynz( ret.sessionCommand, sessionCommand, sizeof( ret.sessionCommand ) );
break;
}
@ -4836,7 +4836,7 @@ idGameLocal::GetBestGameType
*/
void idGameLocal::GetBestGameType( const char* map, const char* gametype, char buf[ MAX_STRING_CHARS ] ) {
idStr aux = mpGame.GetBestGametype( map, gametype );
strncpy( buf, aux.c_str(), MAX_STRING_CHARS );
idStr::Copynz( buf, aux.c_str(), MAX_STRING_CHARS );
buf[ MAX_STRING_CHARS - 1 ] = '\0';
}

View file

@ -1566,7 +1566,7 @@ gameReturn_t idGameLocal::ClientPrediction( int clientNum, const usercmd_t *clie
}
if ( sessionCommand.Length() ) {
strncpy( ret.sessionCommand, sessionCommand, sizeof( ret.sessionCommand ) );
idStr::Copynz( ret.sessionCommand, sessionCommand, sizeof( ret.sessionCommand ) );
}
return ret;
}

View file

@ -2373,7 +2373,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) {
// see if a target_sessionCommand has forced a changelevel
if ( sessionCommand.Length() ) {
strncpy( ret.sessionCommand, sessionCommand, sizeof( ret.sessionCommand ) );
idStr::Copynz( ret.sessionCommand, sessionCommand, sizeof( ret.sessionCommand ) );
break;
}
@ -4338,7 +4338,7 @@ idGameLocal::GetBestGameType
============
*/
void idGameLocal::GetBestGameType( const char* map, const char* gametype, char buf[ MAX_STRING_CHARS ] ) {
strncpy( buf, gametype, MAX_STRING_CHARS );
idStr::Copynz( buf, gametype, MAX_STRING_CHARS );
buf[ MAX_STRING_CHARS - 1 ] = '\0';
}

View file

@ -1521,7 +1521,7 @@ gameReturn_t idGameLocal::ClientPrediction( int clientNum, const usercmd_t *clie
}
if ( sessionCommand.Length() ) {
strncpy( ret.sessionCommand, sessionCommand, sizeof( ret.sessionCommand ) );
idStr::Copynz( ret.sessionCommand, sessionCommand, sizeof( ret.sessionCommand ) );
}
return ret;
}

View file

@ -1275,7 +1275,7 @@ const char *Mem_CleanupFileName( const char *fileName ) {
newFileName = newFileName.Left( i2 - 1 ) + newFileName.Right( newFileName.Length() - ( i1 + 4 ) );
}
index = ( index + 1 ) & 3;
strncpy( newFileNames[index], newFileName.c_str(), sizeof( newFileNames[index] ) );
idStr::Copynz( newFileNames[index], newFileName.c_str(), sizeof( newFileNames[index] ) );
return newFileNames[index];
}