From 5e0ed11a43e37e50ba0937beaa40851c2d864981 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Wed, 7 Sep 2022 19:25:06 -0400 Subject: fix gcc12 warning about malloc size Signed-off-by: Thomas E. Dickey --- src/xftrender.c | 11 ++++++++--- 1 file 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; } -- cgit v1.2.1