Fix potential crash where strings fed into any of the text functions have a trailing '\b'/'\x08'

This commit is contained in:
Simon Robertshaw 2012-06-26 14:31:10 +01:00
parent 694a6ed4f2
commit e26cb8ce2f
3 changed files with 55 additions and 0 deletions

View File

@ -439,8 +439,13 @@ int Graphics::textnwidth(char *s, int n)
break;
if(((char)*s)=='\b')
{
if(!s[1]) break;
s++;
continue;
} else if(*s == '\x0F') {
if(!s[1] || !s[2] || !s[3]) break;
s+=3;
continue;
}
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
n--;
@ -486,8 +491,14 @@ int Graphics::textwidthx(char *s, int w)
{
if((char)*s == '\b')
{
if(!s[1]) break;
s++;
continue;
} else if (*s == '\x0F')
{
if(!s[1] || !s[2] || !s[3]) break;
s+=3;
continue;
}
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
if (x+(cw/2) >= w)
@ -547,8 +558,14 @@ int Graphics::textwrapheight(char *s, int width)
}
else if (*s == '\b')
{
if(!s[1]) break;
s++;
}
else if (*s == '\x0F')
{
if(!s[1] || !s[2] || !s[3]) break;
s+=3;
}
else
{
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
@ -581,8 +598,14 @@ void Graphics::textsize(const char * s, int & width, int & height)
cWidth = 0;
cHeight += FONT_H+2;
}
else if (*s == '\x0F')
{
if(!s[1] || !s[2] || !s[1]) break;
s+=3;
}
else if (*s == '\b')
{
if(!s[1]) break;
s++;
}
else

View File

@ -70,6 +70,7 @@ int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
{
if(!strlen(s))
return 0;
int oR = r, oG = g, oB = b;
int width, height;
Graphics::textsize(s, width, height);
VideoBuffer texture(width, height);
@ -82,8 +83,23 @@ int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
characterX = startX;
characterY += FONT_H+2;
}
else if (*s == '\x0F')
{
if(!s[1] || !s[2] || !s[3]) break;
r = s[1];
g = s[2];
b = s[3];
s += 3;
}
else if (*s == '\x0E')
{
r = oR;
g = oG;
b = oB;
}
else if (*s == '\b')
{
if(!s[1]) break;
switch (s[1])
{
case 'w':

View File

@ -6,6 +6,7 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
return 0;
int width, height;
int oR = r, oG = g, oB = b;
int characterX = x, characterY = y;
int startX = characterX;
for (; *s; s++)
@ -15,8 +16,23 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
characterX = startX;
characterY += FONT_H+2;
}
else if (*s == '\x0F')
{
if(!s[1] || !s[2] || !s[3]) break;
r = s[1];
g = s[2];
b = s[3];
s += 3;
}
else if (*s == '\x0E')
{
r = oR;
g = oG;
b = oB;
}
else if (*s == '\b')
{
if(!s[1]) break;
switch (s[1])
{
case 'w':