Skip to content

Commit cc382b4

Browse files
committed
fix(font): Prevent possibility of creating invalid fonts with zero size
1 parent 392d7ae commit cc382b4

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,8 @@ FontCharsClass::Update_Current_Buffer (int char_width)
15071507
void
15081508
FontCharsClass::Create_GDI_Font (const char *font_name)
15091509
{
1510+
WWASSERT(PointSize > 0);
1511+
15101512
HDC screen_dc = ::GetDC ((HWND)WW3D::Get_Window());
15111513

15121514
const char *fontToUseForGenerals = "Arial";

Generals/Code/GameEngine/Source/GameClient/GUI/GameFont.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ void FontLibrary::reset( void )
178178
//-------------------------------------------------------------------------------------------------
179179
GameFont *FontLibrary::getFont( AsciiString name, Int pointSize, Bool bold )
180180
{
181+
// sanity check the size - anything over 100 is probably wrong. -MW
182+
// TheSuperHackers @fix Now also no longer creates fonts with zero size.
183+
if (pointSize < 1 || pointSize > 100)
184+
{
185+
return NULL;
186+
}
187+
181188
GameFont *font;
182189

183190
// search for font in list

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/W3DGameFont.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,13 @@
7373
//=============================================================================
7474
Bool W3DFontLibrary::loadFontData( GameFont *font )
7575
{
76-
FontCharsClass *fontChar;
77-
7876
// sanity
7977
if( font == NULL )
8078
return FALSE;
8179

82-
if ((UnsignedInt)font->pointSize > 100) //sanity check the size - anything over 100 is probably wrong. -MW
83-
fontChar = NULL;
84-
else
85-
{ // get the font data from the asset manager
86-
fontChar = WW3DAssetManager::
87-
Get_Instance()->Get_FontChars( font->nameString.str(), font->pointSize,
88-
font->bold ? true : false );
89-
}
80+
// get the font data from the asset manager
81+
FontCharsClass *fontChar = WW3DAssetManager::Get_Instance()->Get_FontChars(
82+
font->nameString.str(), font->pointSize, font->bold ? true : false );
9083

9184
if( fontChar == NULL )
9285
{

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameFont.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ void FontLibrary::reset( void )
178178
//-------------------------------------------------------------------------------------------------
179179
GameFont *FontLibrary::getFont( AsciiString name, Int pointSize, Bool bold )
180180
{
181+
// sanity check the size - anything over 100 is probably wrong. -MW
182+
// TheSuperHackers @fix Now also no longer creates fonts with zero size.
183+
if (pointSize < 1 || pointSize > 100)
184+
{
185+
return NULL;
186+
}
187+
181188
GameFont *font;
182189

183190
// search for font in list

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/W3DGameFont.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,13 @@
7373
//=============================================================================
7474
Bool W3DFontLibrary::loadFontData( GameFont *font )
7575
{
76-
FontCharsClass *fontChar;
77-
7876
// sanity
7977
if( font == NULL )
8078
return FALSE;
8179

82-
if ((UnsignedInt)font->pointSize > 100) //sanity check the size - anything over 100 is probably wrong. -MW
83-
fontChar = NULL;
84-
else
85-
{ // get the font data from the asset manager
86-
fontChar = WW3DAssetManager::
87-
Get_Instance()->Get_FontChars( font->nameString.str(), font->pointSize,
88-
font->bold ? true : false );
89-
}
80+
// get the font data from the asset manager
81+
FontCharsClass *fontChar = WW3DAssetManager::Get_Instance()->Get_FontChars(
82+
font->nameString.str(), font->pointSize, font->bold ? true : false );
9083

9184
if( fontChar == NULL )
9285
{

0 commit comments

Comments
 (0)