Fixed bug where a bad access would occur when a string was exactly 1

character long and the code relies on CharCount for determining the
string length.


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1570 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
meep-eep
2005-03-05 19:40:06 +00:00
parent 3da6407d41
commit 9e580177b8
+20 -6
View File
@@ -163,9 +163,12 @@ TextRect (PTEXT lpText, PRECT pRect, PBYTE pdelta)
bot_y = 0; bot_y = 0;
width = 0; width = 0;
pStr = lpText->pStr; pStr = lpText->pStr;
if (num_chars > 0)
{
next_ch = getCharFromString (&pStr); next_ch = getCharFromString (&pStr);
if (next_ch == '\0') if (next_ch == '\0')
num_chars = 0; num_chars = 0;
}
while (num_chars--) while (num_chars--)
{ {
wchar_t ch; wchar_t ch;
@@ -175,12 +178,15 @@ TextRect (PTEXT lpText, PRECT pRect, PBYTE pdelta)
last_width = width; last_width = width;
ch = next_ch; ch = next_ch;
if (num_chars > 0)
{
next_ch = getCharFromString (&pStr); next_ch = getCharFromString (&pStr);
if (next_ch == '\0') if (next_ch == '\0')
{ {
lpText->CharCount -= num_chars; lpText->CharCount -= num_chars;
num_chars = 0; num_chars = 0;
} }
}
charFrame = getCharFrame (FontPtr, ch); charFrame = getCharFrame (FontPtr, ch);
if (charFrame != NULL && GetFrameWidth (charFrame)) if (charFrame != NULL && GetFrameWidth (charFrame))
@@ -241,32 +247,38 @@ _text_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
{ {
FONTPTR FontPtr; FONTPTR FontPtr;
FontPtr = _CurFontPtr;
if (FontPtr != 0)
{
COUNT num_chars; COUNT num_chars;
wchar_t next_ch; wchar_t next_ch;
const unsigned char *pStr; const unsigned char *pStr;
TEXTPTR TextPtr; TEXTPTR TextPtr;
PRIMITIVE locPrim; PRIMITIVE locPrim;
TFB_Palette color; TFB_Palette color;
DWORD c32k;
FontPtr = _CurFontPtr;
if (FontPtr == NULL)
return;
if (FontEffect.Use) if (FontEffect.Use)
SetPrimType (&locPrim, STAMP_PRIM); SetPrimType (&locPrim, STAMP_PRIM);
else else
SetPrimType (&locPrim, STAMPFILL_PRIM); SetPrimType (&locPrim, STAMPFILL_PRIM);
c32k = _get_context_fg_color () >> 8;
{
DWORD c32k = _get_context_fg_color () >> 8;
color.r = (UBYTE)((c32k >> (10 - (8 - 5))) & 0xF8); color.r = (UBYTE)((c32k >> (10 - (8 - 5))) & 0xF8);
color.g = (UBYTE)((c32k >> (5 - (8 - 5))) & 0xF8); color.g = (UBYTE)((c32k >> (5 - (8 - 5))) & 0xF8);
color.b = (UBYTE)((c32k << (8 - 5)) & 0xF8); color.b = (UBYTE)((c32k << (8 - 5)) & 0xF8);
}
TextPtr = &PrimPtr->Object.Text; TextPtr = &PrimPtr->Object.Text;
locPrim.Object.Stamp.origin.x = _save_stamp.origin.x; locPrim.Object.Stamp.origin.x = _save_stamp.origin.x;
locPrim.Object.Stamp.origin.y = TextPtr->baseline.y; locPrim.Object.Stamp.origin.y = TextPtr->baseline.y;
num_chars = TextPtr->CharCount; num_chars = TextPtr->CharCount;
if (num_chars == 0)
return;
pStr = TextPtr->pStr; pStr = TextPtr->pStr;
next_ch = getCharFromString (&pStr); next_ch = getCharFromString (&pStr);
if (next_ch == '\0') if (next_ch == '\0')
num_chars = 0; num_chars = 0;
@@ -275,9 +287,12 @@ _text_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
wchar_t ch; wchar_t ch;
ch = next_ch; ch = next_ch;
if (num_chars > 0)
{
next_ch = getCharFromString (&pStr); next_ch = getCharFromString (&pStr);
if (next_ch == '\0') if (next_ch == '\0')
num_chars = 0; num_chars = 0;
}
locPrim.Object.Stamp.frame = getCharFrame (FontPtr, ch); locPrim.Object.Stamp.frame = getCharFrame (FontPtr, ch);
if (locPrim.Object.Stamp.frame != NULL && if (locPrim.Object.Stamp.frame != NULL &&
@@ -319,7 +334,6 @@ _text_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
#endif #endif
} }
} }
}
} }
static inline FRAME_DESC * static inline FRAME_DESC *