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
+83 -69
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;
next_ch = getCharFromString (&pStr); if (num_chars > 0)
if (next_ch == '\0') {
num_chars = 0; next_ch = getCharFromString (&pStr);
if (next_ch == '\0')
num_chars = 0;
}
while (num_chars--) while (num_chars--)
{ {
wchar_t ch; wchar_t ch;
@@ -175,11 +178,14 @@ TextRect (PTEXT lpText, PRECT pRect, PBYTE pdelta)
last_width = width; last_width = width;
ch = next_ch; ch = next_ch;
next_ch = getCharFromString (&pStr); if (num_chars > 0)
if (next_ch == '\0')
{ {
lpText->CharCount -= num_chars; next_ch = getCharFromString (&pStr);
num_chars = 0; if (next_ch == '\0')
{
lpText->CharCount -= num_chars;
num_chars = 0;
}
} }
charFrame = getCharFrame (FontPtr, ch); charFrame = getCharFrame (FontPtr, ch);
@@ -241,83 +247,91 @@ _text_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
{ {
FONTPTR FontPtr; FONTPTR FontPtr;
FontPtr = _CurFontPtr; COUNT num_chars;
if (FontPtr != 0) wchar_t next_ch;
{ const unsigned char *pStr;
COUNT num_chars; TEXTPTR TextPtr;
wchar_t next_ch; PRIMITIVE locPrim;
const unsigned char *pStr; TFB_Palette color;
TEXTPTR TextPtr;
PRIMITIVE locPrim;
TFB_Palette color;
DWORD c32k;
if (FontEffect.Use) FontPtr = _CurFontPtr;
SetPrimType (&locPrim, STAMP_PRIM); if (FontPtr == NULL)
else return;
SetPrimType (&locPrim, STAMPFILL_PRIM);
c32k = _get_context_fg_color () >> 8; if (FontEffect.Use)
SetPrimType (&locPrim, STAMP_PRIM);
else
SetPrimType (&locPrim, STAMPFILL_PRIM);
{
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);
if (next_ch == '\0') next_ch = getCharFromString (&pStr);
num_chars = 0; if (next_ch == '\0')
while (num_chars--) num_chars = 0;
while (num_chars--)
{
wchar_t ch;
ch = next_ch;
if (num_chars > 0)
{ {
wchar_t ch;
ch = next_ch;
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 &&
GetFrameWidth (locPrim.Object.Stamp.frame)) GetFrameWidth (locPrim.Object.Stamp.frame))
{
RECT r;
r.corner.x = locPrim.Object.Stamp.origin.x
- ((FRAMEPTR)locPrim.Object.Stamp.frame)->HotSpot.x;
r.corner.y = locPrim.Object.Stamp.origin.y
- ((FRAMEPTR)locPrim.Object.Stamp.frame)->HotSpot.y;
r.extent.width = GetFrameWidth (locPrim.Object.Stamp.frame);
r.extent.height = GetFrameHeight (locPrim.Object.Stamp.frame);
_save_stamp.origin = r.corner;
if (BoxIntersect (&r, pClipRect, &r))
{ {
RECT r; if (FontEffect.Use)
r.corner.x = locPrim.Object.Stamp.origin.x
- ((FRAMEPTR)locPrim.Object.Stamp.frame)->HotSpot.x;
r.corner.y = locPrim.Object.Stamp.origin.y
- ((FRAMEPTR)locPrim.Object.Stamp.frame)->HotSpot.y;
r.extent.width = GetFrameWidth (locPrim.Object.Stamp.frame);
r.extent.height = GetFrameHeight (locPrim.Object.Stamp.frame);
_save_stamp.origin = r.corner;
if (BoxIntersect (&r, pClipRect, &r))
{ {
if (FontEffect.Use) FRAME origFrame = locPrim.Object.Stamp.frame;
{ locPrim.Object.Stamp.frame = Build_Font_Effect(
FRAME origFrame = locPrim.Object.Stamp.frame; locPrim.Object.Stamp.frame, FontEffect.from,
locPrim.Object.Stamp.frame = Build_Font_Effect( FontEffect.to, FontEffect.type);
locPrim.Object.Stamp.frame, FontEffect.from, TFB_Prim_Stamp (&locPrim.Object.Stamp);
FontEffect.to, FontEffect.type); DestroyDrawable (ReleaseDrawable (
TFB_Prim_Stamp (&locPrim.Object.Stamp); locPrim.Object.Stamp.frame));
DestroyDrawable (ReleaseDrawable ( locPrim.Object.Stamp.frame = origFrame;
locPrim.Object.Stamp.frame));
locPrim.Object.Stamp.frame = origFrame;
}
else
TFB_Prim_StampFill (&locPrim.Object.Stamp, &color);
} }
else
locPrim.Object.Stamp.origin.x += GetFrameWidth ( TFB_Prim_StampFill (&locPrim.Object.Stamp, &color);
locPrim.Object.Stamp.frame);
#if 0
if (num_chars && next_ch < (UNICODE) MAX_CHARS
&& !(FontPtr->KernTab[ch]
& (FontPtr->KernTab[next_ch] >> 2)))
locPrim.Object.Stamp.origin.x -= FontPtr->KernAmount;
#endif
} }
locPrim.Object.Stamp.origin.x += GetFrameWidth (
locPrim.Object.Stamp.frame);
#if 0
if (num_chars && next_ch < (UNICODE) MAX_CHARS
&& !(FontPtr->KernTab[ch]
& (FontPtr->KernTab[next_ch] >> 2)))
locPrim.Object.Stamp.origin.x -= FontPtr->KernAmount;
#endif
} }
} }
} }