More safe strncpy usage.

This commit is contained in:
Andrey Akhmichin 2022-11-16 07:12:11 +05:00
parent 9033377e5e
commit e6424f42a7
No known key found for this signature in database
GPG Key ID: 1F180D249B0643C0
1 changed files with 4 additions and 3 deletions

View File

@ -263,7 +263,8 @@ ParticleType *ParticleSystem::GetType( const char *szName )
ParticleType *ParticleSystem::AddPlaceholderType( const char *szName )
{
m_pFirstType = new ParticleType( m_pFirstType );
strncpy(m_pFirstType->m_szName, szName, sizeof(m_pFirstType->m_szName) );
strncpy(m_pFirstType->m_szName, szName, sizeof(m_pFirstType->m_szName) - 1);
m_pFirstType->m_szName[sizeof(m_pFirstType->m_szName) - 1] = '\0';
return m_pFirstType;
}
@ -285,8 +286,8 @@ ParticleType *ParticleSystem::ParseType( char *&szFile )
if ( !stricmp( szToken, "name" ) )
{
szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
strncpy(pType->m_szName, szToken, sizeof(pType->m_szName) );
strncpy(pType->m_szName, szToken, sizeof(pType->m_szName) - 1 );
pType->m_szName[sizeof(pType->m_szName) - 1] = '\0';
ParticleType *pTemp = GetType(szToken);
if (pTemp)
{