Browse Source

More safe strncpy usage.

dmc
Andrey Akhmichin 2 years ago
parent
commit
eb1ce63384
No known key found for this signature in database
GPG Key ID: 1F180D249B0643C0
  1. 5
      cl_dll/statusbar.cpp
  2. 9
      dlls/3wave/threewave_gamerules.cpp

5
cl_dll/statusbar.cpp

@ -78,11 +78,12 @@ void CHudStatusBar::ParseStatusString( int line_num ) @@ -78,11 +78,12 @@ void CHudStatusBar::ParseStatusString( int line_num )
GetPlayerInfo( indexval, &g_PlayerInfoList[indexval] );
if( g_PlayerInfoList[indexval].name != NULL )
{
strncpy( m_szName[line_num], g_PlayerInfoList[indexval].name, MAX_PLAYER_NAME_LENGTH );
strncpy( m_szName[line_num], g_PlayerInfoList[indexval].name, MAX_PLAYER_NAME_LENGTH - 1 );
m_szName[line_num][MAX_PLAYER_NAME_LENGTH - 1] = '\0';
}
else
{
strncpy( m_szName[line_num], "******", MAX_PLAYER_NAME_LENGTH );
strcpy( m_szName[line_num], "******" );
}
g_iNameColors = GetTeamIndex( indexval );

9
dlls/3wave/threewave_gamerules.cpp

@ -98,7 +98,8 @@ CThreeWave::CThreeWave() @@ -98,7 +98,8 @@ CThreeWave::CThreeWave()
m_szTeamList[0] = 0;
// Cache this because the team code doesn't want to deal with changing this in the middle of a game
strncpy( m_szTeamList, teamlist.string, TEAMPLAY_TEAMLISTLENGTH );
strncpy( m_szTeamList, teamlist.string, TEAMPLAY_TEAMLISTLENGTH - 1 );
m_szTeamList[TEAMPLAY_TEAMLISTLENGTH - 1] = '\0';
edict_t *pWorld = INDEXENT( 0 );
if( pWorld && pWorld->v.team )
@ -108,7 +109,8 @@ CThreeWave::CThreeWave() @@ -108,7 +109,8 @@ CThreeWave::CThreeWave()
const char *pTeamList = STRING( pWorld->v.team );
if( pTeamList && strlen( pTeamList ) )
{
strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH );
strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH - 1 );
m_szTeamList[TEAMPLAY_TEAMLISTLENGTH - 1] = '\0';
}
}
}
@ -1426,7 +1428,8 @@ void CThreeWave::RecountTeams() @@ -1426,7 +1428,8 @@ void CThreeWave::RecountTeams()
tm = num_teams;
num_teams++;
team_scores[tm] = 0;
strncpy( team_names[tm], pTeamName, MAX_TEAMNAME_LENGTH );
strncpy( team_names[tm], pTeamName, MAX_TEAMNAME_LENGTH - 1 );
team_names[tm][MAX_TEAMNAME_LENGTH - 1] = '\0';
}
}

Loading…
Cancel
Save