Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,13 @@ FontCharsClass::Get_Char_Data (WCHAR ch)
else
{
Grow_Unicode_Array( ch );
retval = UnicodeCharArray[ch - FirstUnicodeChar];

//
// Validate that the UnicodeCharArray is properly allocated and the index is valid
//
if ( UnicodeCharArray != NULL && ch >= FirstUnicodeChar && ch <= LastUnicodeChar ) {
retval = UnicodeCharArray[ch - FirstUnicodeChar];
}
}

//
Expand Down Expand Up @@ -1398,7 +1404,20 @@ FontCharsClass::Store_GDI_Char (WCHAR ch)
// Get a pointer to the surface that this character should use
//
Update_Current_Buffer( char_size.cx );
uint16* curr_buffer_p = BufferList[BufferList.Count () - 1]->Buffer;

//
// Validate that we have a valid buffer before proceeding
//
if ( BufferList.Count () == 0 || BufferList[BufferList.Count () - 1] == NULL ) {
return NULL;
}

//
// Cache the buffer pointer immediately after Update_Current_Buffer()
// to prevent race conditions if BufferList is modified
//
FontCharsBuffer* current_buffer = BufferList[BufferList.Count () - 1];
uint16* curr_buffer_p = current_buffer->Buffer;
curr_buffer_p += CurrPixelOffset;

//
Expand Down Expand Up @@ -1472,15 +1491,26 @@ FontCharsClass::Store_GDI_Char (WCHAR ch)
FontCharsClassCharDataStruct *char_data = W3DNEW FontCharsClassCharDataStruct;
char_data->Value = ch;
char_data->Width = char_size.cx;
char_data->Buffer = BufferList[BufferList.Count () - 1]->Buffer + CurrPixelOffset;
char_data->Buffer = current_buffer->Buffer + CurrPixelOffset;

//
// Insert this character into our array
//
if ( ch < 256 ) {
ASCIICharArray[ch] = char_data;
} else {
UnicodeCharArray[ch - FirstUnicodeChar] = char_data;
//
// Ensure the Unicode array is allocated and the index is valid
//
if ( UnicodeCharArray != NULL && ch >= FirstUnicodeChar && ch <= LastUnicodeChar ) {
UnicodeCharArray[ch - FirstUnicodeChar] = char_data;
} else {
//
// Failed to allocate Unicode array - clean up and return NULL
//
delete char_data;
return NULL;
}
}

//
Expand Down
Loading