Skip to content

Commit 7dc1f10

Browse files
author
Pavel Kovalenko
committed
Fix potential stack overflow in CConsole::DrawBackgrounds.
1 parent 08a7396 commit 7dc1f10

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/xrEngine/XR_IOConsole.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void CConsole::DrawBackgrounds( bool bGame )
438438
if ( m_select_tip < (int)m_tips.size() )
439439
{
440440
Frect r;
441-
441+
xr_string tmp;
442442
vecTipsEx::iterator itb = m_tips.begin() + m_start_tip;
443443
vecTipsEx::iterator ite = m_tips.end();
444444
for ( u32 i = 0; itb != ite; ++itb, ++i ) // tips
@@ -455,14 +455,12 @@ void CConsole::DrawBackgrounds( bool bGame )
455455
}
456456

457457
r.null();
458-
LPSTR tmp = (PSTR)_alloca( (str_size + 1) * sizeof(char) );
459-
460-
strncpy_s( tmp, str_size+1, ts.text.c_str(), ts.HL_start );
461-
r.x1 = pr.x1 + w1 + pFont->SizeOf_( tmp );
458+
tmp.assign(ts.text.c_str(), ts.HL_start);
459+
r.x1 = pr.x1 + w1 + pFont->SizeOf_( tmp.c_str() );
462460
r.y1 = pr.y1 + i * font_h;
463461

464-
strncpy_s( tmp, str_size+1, ts.text.c_str(), ts.HL_finish );
465-
r.x2 = pr.x1 + w1 + pFont->SizeOf_( tmp );
462+
tmp.assign(ts.text.c_str(), ts.HL_finish);
463+
r.x2 = pr.x1 + w1 + pFont->SizeOf_( tmp.c_str() );
466464
r.y2 = r.y1 + font_h;
467465

468466
DrawRect( r, tips_word_color );

0 commit comments

Comments
 (0)