More safe strncpy usage.

This commit is contained in:
Andrey Akhmichin 2022-11-16 05:01:03 +05:00
parent 1dd1f0b154
commit eb1ce63384
No known key found for this signature in database
GPG Key ID: 1F180D249B0643C0
2 changed files with 9 additions and 5 deletions

View File

@ -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 );

View File

@ -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()
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()
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';
}
}