Skip to content

Commit

Permalink
Fix negative glyph index in Team Arena text functions
Browse files Browse the repository at this point in the history
Team Arena's text functions cast signed char values to int and use as an array index.
This works fine for values 0 to 127, but not for -128 to -1 which are a negative array index.
Instead use "character & 255" like client and original Q3 ui/cgame string drawing code.
  • Loading branch information
zturtleman committed Dec 2, 2014
1 parent 08ddb99 commit b21a59a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
12 changes: 3 additions & 9 deletions code/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ int CG_Text_Width(const char *text, float scale, int limit) {
float out;
glyphInfo_t *glyph;
float useScale;
// FIXME: see ui_main.c, same problem
// const unsigned char *s = text;
const char *s = text;
fontInfo_t *font = &cgDC.Assets.textFont;
if (scale <= cg_smallFont.value) {
Expand All @@ -71,7 +69,7 @@ int CG_Text_Width(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
out += glyph->xSkip;
s++;
count++;
Expand All @@ -86,8 +84,6 @@ int CG_Text_Height(const char *text, float scale, int limit) {
float max;
glyphInfo_t *glyph;
float useScale;
// TTimo: FIXME
// const unsigned char *s = text;
const char *s = text;
fontInfo_t *font = &cgDC.Assets.textFont;
if (scale <= cg_smallFont.value) {
Expand All @@ -108,7 +104,7 @@ int CG_Text_Height(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if (max < glyph->height) {
max = glyph->height;
}
Expand Down Expand Up @@ -141,8 +137,6 @@ void CG_Text_Paint(float x, float y, float scale, vec4_t color, const char *text
}
useScale = scale * font->glyphScale;
if (text) {
// TTimo: FIXME
// const unsigned char *s = text;
const char *s = text;
trap_R_SetColor( color );
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
Expand All @@ -152,7 +146,7 @@ void CG_Text_Paint(float x, float y, float scale, vec4_t color, const char *text
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
if ( Q_IsColorString( s ) ) {
Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_newdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ static void CG_Text_Paint_Limit(float *maxX, float x, float y, float scale, vec4
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if ( Q_IsColorString( s ) ) {
memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
newColor[3] = color[3];
Expand Down
12 changes: 6 additions & 6 deletions code/ui/ui_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ int Text_Width(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s];
glyph = &font->glyphs[*s & 255];
out += glyph->xSkip;
s++;
count++;
Expand Down Expand Up @@ -319,7 +319,7 @@ int Text_Height(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if (max < glyph->height) {
max = glyph->height;
}
Expand Down Expand Up @@ -361,7 +361,7 @@ void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, f
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
if ( Q_IsColorString( s ) ) {
Expand Down Expand Up @@ -429,9 +429,9 @@ void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const cha
len = limit;
}
count = 0;
glyph2 = &font->glyphs[ (int) cursor];
glyph2 = &font->glyphs[cursor & 255];
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
if ( Q_IsColorString( s ) ) {
Expand Down Expand Up @@ -528,7 +528,7 @@ static void Text_Paint_Limit(float *maxX, float x, float y, float scale, vec4_t
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if ( Q_IsColorString( s ) ) {
memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
newColor[3] = color[3];
Expand Down

0 comments on commit b21a59a

Please sign in to comment.