From 9cc5bb23526611e8d164abd64e02ad6113d412c4 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Tue, 17 May 2022 03:23:12 +0200 Subject: [PATCH] Use idStr::Copynz() instead of strncpy() to guarantee \0-termination (only the applicable parts of that dhewm3 commit) --- d3xp/Game_local.cpp | 4 ++-- d3xp/Game_network.cpp | 2 +- game/Game_local.cpp | 4 ++-- game/Game_network.cpp | 2 +- idlib/Heap.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/d3xp/Game_local.cpp b/d3xp/Game_local.cpp index 87fb4ab..0489186 100644 --- a/d3xp/Game_local.cpp +++ b/d3xp/Game_local.cpp @@ -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'; } diff --git a/d3xp/Game_network.cpp b/d3xp/Game_network.cpp index 36d799e..7c3bb14 100644 --- a/d3xp/Game_network.cpp +++ b/d3xp/Game_network.cpp @@ -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; } diff --git a/game/Game_local.cpp b/game/Game_local.cpp index 35b5202..ae1eb86 100644 --- a/game/Game_local.cpp +++ b/game/Game_local.cpp @@ -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'; } diff --git a/game/Game_network.cpp b/game/Game_network.cpp index c26d906..d7e2268 100644 --- a/game/Game_network.cpp +++ b/game/Game_network.cpp @@ -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; } diff --git a/idlib/Heap.cpp b/idlib/Heap.cpp index a76fb4a..e69f008 100644 --- a/idlib/Heap.cpp +++ b/idlib/Heap.cpp @@ -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]; }