Skip to content

Commit

Permalink
fix buffer overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
YoYo178 committed Mar 8, 2024
1 parent c4b0f99 commit 4b3bb4c
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion mp/src/game/client/ff/hud/ff_hud_cellcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void CHudCellCount::Paint()

// Get the class as a string
wchar_t unicode[6];
swprintf(unicode, L"%d", m_iCellCount);
V_snwprintf(unicode, sizeof(unicode), L"%d", m_iCellCount);

// Draw text
surface()->DrawSetTextFont( m_hTextFont );
Expand Down
4 changes: 2 additions & 2 deletions mp/src/game/client/ff/hud/ff_hud_hitindicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void CHudHitIndicator::Paint( void )
int charOffsetX = surface()->GetCharacterWidth(currentFont, outerChar) / 2;
int charOffsetY = surface()->GetFontTall(currentFont) / 2;

swprintf(unicode, L"%c", outerChar);
V_snwprintf(unicode, sizeof(unicode), L"%c", outerChar);

surface()->DrawSetTextPos(x - charOffsetX, y - charOffsetY);
surface()->DrawUnicodeChar(unicode[0]);
Expand All @@ -262,7 +262,7 @@ void CHudHitIndicator::Paint( void )
charOffsetX = surface()->GetCharacterWidth(currentFont, innerChar) / 2;
charOffsetY = surface()->GetFontTall(currentFont) / 2;

swprintf(unicode, L"%c", innerChar);
V_snwprintf(unicode, sizeof(unicode), L"%c", innerChar);

surface()->DrawSetTextPos(x - charOffsetX, y - charOffsetY);
surface()->DrawUnicodeChar(unicode[0]);
Expand Down
4 changes: 2 additions & 2 deletions mp/src/game/client/ff/hud/ff_hud_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ void CHudContextMenu::Paint()
int iconOffsetY = surface()->GetFontTall(m_hMenuIcon) / 2;

wchar_t unicode[2];
swprintf(unicode, L"%c", character);
V_snwprintf(unicode, sizeof(unicode), L"%c", character);

surface()->DrawSetTextPos(m_flPositions[i][0] - iconOffsetX, m_flPositions[i][1] - iconOffsetY);
surface()->DrawUnicodeChar(unicode[0]);
Expand Down Expand Up @@ -740,7 +740,7 @@ void CHudContextMenu::Paint()
int textHeightX = surface()->GetFontTall(m_hTextFont);
surface()->DrawSetTextPos(m_flPositions[i][0] - numberOffsetX, m_flPositions[i][1] + iconOffsetY + py + textHeightX);

swprintf(unicode, L"%c", chDisplay);
V_snwprintf(unicode, sizeof(unicode), L"%c", chDisplay);
surface()->DrawUnicodeChar(unicode[0]);
}

Expand Down
4 changes: 2 additions & 2 deletions mp/src/game/client/ff/hud/ff_hud_speedometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void CHudSpeedometer::Paint()
surface()->DrawSetTextPos( SpeedFont_xpos, SpeedFont_ypos );

wchar_t unicode[6];
swprintf(unicode, L"%d", (int)m_iVelocity);
V_snwprintf(unicode, sizeof(unicode), L"%d", (int)m_iVelocity);

for( wchar_t *wch = unicode; *wch != 0; wch++ )
surface()->DrawUnicodeChar( *wch );
Expand Down Expand Up @@ -237,7 +237,7 @@ void CHudSpeedometer::Paint()
surface()->DrawSetTextColor( speedColor );

wchar_t unicode[6];
swprintf(unicode, L"%d", (int)m_flAvgVelocity);
V_snwprintf(unicode, sizeof(unicode), L"%d", (int)m_flAvgVelocity);

for( wchar_t *wch = unicode; *wch != 0; wch++ )
surface()->DrawUnicodeChar( *wch );
Expand Down
6 changes: 3 additions & 3 deletions mp/src/game/client/ff/hud/ff_hud_teamscores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void CHudTeamScores::PaintNumbersRightAligned(HFont font, int xpos, int ypos, in
int iTempxpos = xpos + charWidth * maxchars; // allow for X characters of score

wchar_t unicode[6];
swprintf(unicode, L"%d", value);
V_snwprintf(unicode, sizeof(unicode), L"%d", value);

surface()->DrawSetTextFont( font );

Expand All @@ -185,7 +185,7 @@ void CHudTeamScores::PaintNumbers(HFont font, int xpos, int ypos, int value)
{
surface()->DrawSetTextFont(font);
wchar_t unicode[6];
swprintf(unicode, L"%d", value);
V_snwprintf(unicode, sizeof(unicode), L"%d", value);
surface()->DrawSetTextPos(xpos, ypos);
surface()->DrawUnicodeString( unicode );
}
}
10 changes: 5 additions & 5 deletions mp/src/game/client/game_controls/ClientScoreBoardDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,23 +622,23 @@ void CClientScoreBoardDialog::UpdateHeaders( void )
}
else
{
swprintf( szName, L"%s - (%i players)", szTeamName, iNumPlayers );
V_snwprintf( szName, sizeof(szName), L"%s - (%i players)", szTeamName, iNumPlayers );
szTeamName = szName;
}

m_pPlayerList->ModifyColumn( i, "name", szTeamName );

// Look up team fort points (currently hacked to get team score (frags) which is what was previously used)
wchar_t szFortPoints[ 6 ];
swprintf( szFortPoints, L"%d", pGR->GetTeamScore( iTeam ) );
V_snwprintf( szFortPoints, sizeof(szFortPoints), L"%d", pGR->GetTeamScore( iTeam ) );

// Display team fort points (probably will actually be team score e.g. captures *10)
m_pPlayerList->ModifyColumn( i, "fortpoints", szFortPoints );

// AfterShock - commented this out so teamfrags arent shown (and scores are clearer)
// Look up team score (frags)
//wchar_t szScore[ 6 ];
//swprintf( szScore, L"%d", pGR->GetTeamScore( iTeam ) );
//V_snwprintf( szScore, sizeof(szScore), L"%d", pGR->GetTeamScore( iTeam ) );

// Display team frags
//m_pPlayerList->ModifyColumn( i, "score", szScore );
Expand All @@ -647,7 +647,7 @@ void CClientScoreBoardDialog::UpdateHeaders( void )
// AfterShock - commented this out so teamdeaths arent shown (and scores are clearer)
// Look up team deaths
//wchar_t szDeaths[ 6 ];
//swprintf( szDeaths, L"%d", pGR->GetTeamDeaths( iTeam ) );
//V_snwprintf( szDeaths, sizeof(szDeaths), L"%d", pGR->GetTeamDeaths( iTeam ) );

// Display team deaths
//m_pPlayerList->ModifyColumn( i, "deaths", szDeaths );
Expand All @@ -664,7 +664,7 @@ void CClientScoreBoardDialog::UpdateHeaders( void )
else
{
wchar_t szLatency[ 12 ];
swprintf( szLatency, L"%i", iLatency );
V_snwprintf( szLatency, sizeof(szLatency), L"%i", iLatency );
m_pPlayerList->ModifyColumn( i, "ping", szLatency );
}
}
Expand Down
2 changes: 1 addition & 1 deletion mp/src/game/client/game_controls/classmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class LoadoutLabel : public Label
char character = pIcon->cCharacterInFont;

wchar_t unicode[2];
swprintf(unicode, L"%c", character);
V_snwprintf(unicode, sizeof(unicode), L"%c", character);

surface()->DrawSetTextColor(Color(255, 255, 255, 255));
surface()->DrawSetTextFont(hFont);
Expand Down
4 changes: 2 additions & 2 deletions mp/src/game/client/game_controls/teammenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void CTeamMenu::UpdateTeamButtons()

if (szTeamName)
{
swprintf( szName, L"%c. %s", wchTeamNumber, szTeamName );
V_snwprintf( szName, sizeof(szName), L"%c. %s", wchTeamNumber, szTeamName );
szTeamName = szName;
}
else
Expand All @@ -482,7 +482,7 @@ void CTeamMenu::UpdateTeamButtons()
else
{
// no name, just use the number
swprintf( szTeamName, L"%c.", wchTeamNumber );
V_snwprintf( szTeamName, sizeof(szTeamName), L"%c.", wchTeamNumber );
pTeamButton->SetText(szTeamName);
}

Expand Down
6 changes: 3 additions & 3 deletions mp/src/game/client/hud_crosshair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void CHudCrosshair::Paint(void)
int charOffsetX = surface()->GetCharacterWidth(currentFont, outerChar) / 2;
int charOffsetY = surface()->GetFontTall(currentFont) / 2;

swprintf(unicode, L"%c", outerChar);
V_snwprintf(unicode, sizeof(unicode), L"%c", outerChar);

surface()->DrawSetTextPos(x - charOffsetX, y - charOffsetY);
surface()->DrawUnicodeChar(unicode[0]);
Expand All @@ -430,7 +430,7 @@ void CHudCrosshair::Paint(void)
charOffsetX = surface()->GetCharacterWidth(currentFont, innerChar) / 2;
charOffsetY = surface()->GetFontTall(currentFont) / 2;

swprintf(unicode, L"%c", innerChar);
V_snwprintf(unicode, sizeof(unicode), L"%c", innerChar);

surface()->DrawSetTextPos(x - charOffsetX, y - charOffsetY);
surface()->DrawUnicodeChar(unicode[0]);
Expand Down Expand Up @@ -557,4 +557,4 @@ void CHudCrosshair::SetCrosshair(CHudTexture* texture, const Color& clr)
void CHudCrosshair::ResetCrosshair()
{
SetCrosshair(m_pDefaultCrosshair, Color(255, 255, 255, 255));
}
}
2 changes: 1 addition & 1 deletion mp/src/game/client/hud_numericdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void CHudNumericDisplay::PaintNumbersRightAligned(HFont font, int xpos, int ypos
int iTempxpos = xpos + charWidth * maxchars; // allow for X characters of score

wchar_t unicode[6];
swprintf(unicode, L"%d", value);
V_snwprintf(unicode, sizeof(unicode), L"%d", value);

surface()->DrawSetTextFont(font);

Expand Down

0 comments on commit 4b3bb4c

Please sign in to comment.