summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2022-09-07 19:25:06 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2022-09-07 19:26:49 -0400
commit5e0ed11a43e37e50ba0937beaa40851c2d864981 (patch)
treebf99191297485fc25d09943d8d0e2288ec876ef7
parentab2df0af3dc7c594d44ccccfa0e7ddeeefb1e70e (diff)
downloadxorg-lib-libXft-5e0ed11a43e37e50ba0937beaa40851c2d864981.tar.gz
fix gcc12 warning about malloc size
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
-rw-r--r--src/xftrender.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/xftrender.c b/src/xftrender.c
index bf2d494..3021d56 100644
--- a/src/xftrender.c
+++ b/src/xftrender.c
@@ -88,7 +88,7 @@ XftGlyphRender (Display *dpy,
FT_UInt missing[XFT_NMISSING];
int nmissing;
FT_UInt g, max;
- int size, width;
+ int width;
int dstx, dsty;
Glyph wire;
XftGlyph* glyph;
@@ -98,6 +98,8 @@ XftGlyphRender (Display *dpy,
unsigned int char_local[NUM_LOCAL];
unsigned int *chars;
FcBool glyphs_loaded;
+ size_t size;
+ size_t needed;
if (!font->format)
return;
@@ -137,9 +139,12 @@ XftGlyphRender (Display *dpy,
size = sizeof (unsigned int);
}
chars = char_local;
- if ((size_t) (nglyphs * size) > sizeof (char_local))
+ if ((size_t)nglyphs > SIZE_MAX / size)
+ goto bail1;
+ needed = (size_t)nglyphs * size;
+ if (needed > sizeof (char_local))
{
- chars = malloc ((size_t)(nglyphs * size));
+ chars = malloc (needed);
if (!chars)
goto bail1;
}