grOGL3.c: add GrOGLTextSize() error return

'textrect' is not filled in when GrOGLTextSize() fails.

Add error return and abort groglPutText() easrly on error.

graphics/grOGL3.c:783 Rect textrect;

SonarCloud
The right operand of '+' is a garbage value
https://sonarcloud.io/project/issues?open=AZJB160qNGfDNup0Riv5&id=dlmiles_magic
This commit is contained in:
Darryl L. Miles 2024-10-04 20:27:53 +01:00 committed by Tim Edwards
parent 56317e6583
commit 86b5d591d6
1 changed files with 6 additions and 4 deletions

View File

@ -257,7 +257,7 @@ groglSetCharSize (size)
* Determine the size of a text string.
*
* Results:
* None.
* 0 on success. -1 on error (no side-effects).
*
* Side effects:
* A rectangle is filled in that is the size of the text in pixels.
@ -266,7 +266,7 @@ groglSetCharSize (size)
* ----------------------------------------------------------------------------
*/
void
int
GrOGLTextSize(text, size, r)
char *text;
int size;
@ -296,13 +296,14 @@ GrOGLTextSize(text, size, r)
size );
break;
}
if (font == NULL) return;
if (font == NULL) return -1;
XTextExtents(font, text, strlen(text), &dir, &fa, &fd, &overall);
r->r_ytop = overall.ascent;
r->r_ybot = -overall.descent;
r->r_xtop = overall.width - overall.lbearing;
r->r_xbot = -overall.lbearing - 1;
return 0;
}
@ -787,7 +788,8 @@ groglPutText (text, pos, clip, obscure)
int i;
float tscale;
GrOGLTextSize(text, oglCurrent.fontSize, &textrect);
if (GrOGLTextSize(text, oglCurrent.fontSize, &textrect) < 0)
return;
location.r_xbot = pos->p_x + textrect.r_xbot;
location.r_xtop = pos->p_x + textrect.r_xtop;