diff --git a/neo/d3xp/Game_local.cpp b/neo/d3xp/Game_local.cpp index 9a5db97b..9e1e8669 100644 --- a/neo/d3xp/Game_local.cpp +++ b/neo/d3xp/Game_local.cpp @@ -2655,7 +2655,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; } @@ -4852,7 +4852,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/neo/d3xp/Game_network.cpp b/neo/d3xp/Game_network.cpp index 36d799ee..7c3bb140 100644 --- a/neo/d3xp/Game_network.cpp +++ b/neo/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/neo/framework/Session.cpp b/neo/framework/Session.cpp index a180ac16..da4c6d65 100644 --- a/neo/framework/Session.cpp +++ b/neo/framework/Session.cpp @@ -1461,7 +1461,7 @@ void idSessionLocal::LoadLoadingGui( const char *mapName ) { stripped.StripPath(); char guiMap[ MAX_STRING_CHARS ]; - strncpy( guiMap, va( "guis/map/%s.gui", stripped.c_str() ), MAX_STRING_CHARS ); + idStr::Copynz( guiMap, va( "guis/map/%s.gui", stripped.c_str() ), MAX_STRING_CHARS ); // give the gamecode a chance to override game->GetMapLoadingGUI( guiMap ); diff --git a/neo/game/Game_local.cpp b/neo/game/Game_local.cpp index fd42c320..99f7e0f3 100644 --- a/neo/game/Game_local.cpp +++ b/neo/game/Game_local.cpp @@ -2403,7 +2403,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; } @@ -4368,7 +4368,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/neo/game/Game_network.cpp b/neo/game/Game_network.cpp index c26d9068..d7e22688 100644 --- a/neo/game/Game_network.cpp +++ b/neo/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/neo/idlib/Heap.cpp b/neo/idlib/Heap.cpp index a76fb4ac..e69f0088 100644 --- a/neo/idlib/Heap.cpp +++ b/neo/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]; } diff --git a/neo/renderer/RenderWorld_demo.cpp b/neo/renderer/RenderWorld_demo.cpp index 32ad265e..db94772d 100644 --- a/neo/renderer/RenderWorld_demo.cpp +++ b/neo/renderer/RenderWorld_demo.cpp @@ -277,7 +277,10 @@ void idRenderWorldLocal::WriteLoadMap() { session->writeDemo->WriteInt( DC_LOADMAP ); demoHeader_t header; + // DG: Note: here strncpy() makes sense, because all chars of mapname get written + // so it's good if the ones behind the actual name are *all* \0 strncpy( header.mapname, mapName.c_str(), sizeof( header.mapname ) - 1 ); + header.mapname[sizeof( header.mapname ) - 1] = '\0'; // make sure the last chars is also \0 header.version = 4; header.sizeofRenderEntity = sizeof( renderEntity_t ); header.sizeofRenderLight = sizeof( renderLight_t ); diff --git a/neo/renderer/draw_arb2.cpp b/neo/renderer/draw_arb2.cpp index f55aeb02..3f7f908e 100644 --- a/neo/renderer/draw_arb2.cpp +++ b/neo/renderer/draw_arb2.cpp @@ -630,7 +630,7 @@ int R_FindARBProgram( GLenum target, const char *program ) { // add it to the list and load it progs[i].ident = (program_t)0; // will be gen'd by R_LoadARBProgram progs[i].target = target; - strncpy( progs[i].name, program, sizeof( progs[i].name ) - 1 ); + idStr::Copynz( progs[i].name, program, sizeof( progs[i].name ) ); R_LoadARBProgram( i ); diff --git a/neo/sys/aros/aros_net.cpp b/neo/sys/aros/aros_net.cpp index e61bc0a0..6e5e99f6 100644 --- a/neo/sys/aros/aros_net.cpp +++ b/neo/sys/aros/aros_net.cpp @@ -117,8 +117,7 @@ ExtractPort */ static bool ExtractPort( const char *src, char *buf, int bufsize, int *port ) { char *p; - strncpy( buf, src, bufsize ); - p = buf; p += Min( bufsize - 1, (int)strlen( src ) ); *p = '\0'; + idStr::Copynz( buf, src, bufsize ); p = strchr( buf, ':' ); if ( !p ) { return false; diff --git a/neo/sys/aros/aros_signal.cpp b/neo/sys/aros/aros_signal.cpp index f8626f49..4271c724 100644 --- a/neo/sys/aros/aros_signal.cpp +++ b/neo/sys/aros/aros_signal.cpp @@ -170,5 +170,5 @@ Sys_SetFatalError ================== */ void Sys_SetFatalError( const char *error ) { - strncpy( fatalError, error, sizeof( fatalError ) ); + idStr::Copynz( fatalError, error, sizeof( fatalError ) ); } diff --git a/neo/sys/osx/DOOMController.mm b/neo/sys/osx/DOOMController.mm index 8cc45f9f..8b25bdb2 100644 --- a/neo/sys/osx/DOOMController.mm +++ b/neo/sys/osx/DOOMController.mm @@ -57,7 +57,7 @@ bool Sys_GetPath(sysPath_t type, idStr &path) { switch(type) { case PATH_BASE: - strncpy(buf, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN ); + SDL_strlcpy(buf, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN ); snap = strrchr(buf, '/'); if (snap) *snap = '\0'; @@ -196,7 +196,7 @@ int SDL_main( int argc, char *argv[] ) { Sys_Error("Could not access application resources"); // DG: set exe_path so Posix_InitSignalHandlers() can call Posix_GetExePath() - strncpy(exe_path, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN); + SDL_strlcpy(exe_path, [ [ [ NSBundle mainBundle ] bundlePath ] cString ], MAXPATHLEN); Posix_InitSignalHandlers(); // DG: added signal handlers for POSIX platforms diff --git a/neo/sys/posix/posix_net.cpp b/neo/sys/posix/posix_net.cpp index c7c012de..746a945d 100644 --- a/neo/sys/posix/posix_net.cpp +++ b/neo/sys/posix/posix_net.cpp @@ -109,8 +109,7 @@ ExtractPort */ static bool ExtractPort( const char *src, char *buf, int bufsize, int *port ) { char *p; - strncpy( buf, src, bufsize ); - p = buf; p += Min( bufsize - 1, (int)strlen( src ) ); *p = '\0'; + idStr::Copynz( buf, src, bufsize ); p = strchr( buf, ':' ); if ( !p ) { return false; diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index d263a0a9..03df0d3f 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -1178,6 +1178,7 @@ void idSysLocal::StartProcess( const char *exePath, bool doexit ) { si.cb = sizeof(si); strncpy( szPathOrig, exePath, _MAX_PATH ); + szPathOrig[_MAX_PATH-1] = 0; if( !CreateProcess( NULL, szPathOrig, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ) ) { common->Error( "Could not start process: '%s' ", szPathOrig ); diff --git a/neo/sys/win32/win_net.cpp b/neo/sys/win32/win_net.cpp index fa742d2c..5e4dfc5d 100644 --- a/neo/sys/win32/win_net.cpp +++ b/neo/sys/win32/win_net.cpp @@ -163,8 +163,7 @@ Net_ExtractPort */ static bool Net_ExtractPort( const char *src, char *buf, int bufsize, int *port ) { char *p; - strncpy( buf, src, bufsize ); - p = buf; p += Min( bufsize - 1, (int)strlen( src ) ); *p = '\0'; + idStr::Copynz( buf, src, bufsize ); p = strchr( buf, ':' ); if ( !p ) { return false;