From 8a71c7338c1b08967d57a4c12d5413f531ad7ec2 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 6 May 2025 16:31:45 +0200 Subject: [PATCH] render: glyph: extra NULL pointer protection Even though it's probably never happening, but still better to protect from it, just in case. The extra cost of it hard to measure on today's machines. Signed-off-by: Enrico Weigelt, metux IT consult --- render/glyph.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/render/glyph.c b/render/glyph.c index cc982a038..19ad9cf0b 100644 --- a/render/glyph.c +++ b/render/glyph.c @@ -123,6 +123,10 @@ FindGlyphRef(GlyphHashPtr hash, CARD32 elt, step, s; GlyphPtr glyph; GlyphRefPtr table, gr, del; + + if ((hash == NULL) || (hash->hashSet == NULL)) + return NULL; + CARD32 tableSize = hash->hashSet->size; table = hash->table; @@ -267,7 +271,7 @@ FreeGlyph(GlyphPtr glyph, int format) gr = FindGlyphRef(&globalGlyphs[format], signature, TRUE, glyph->sha1); if (gr - globalGlyphs[format].table != first) DuplicateRef(glyph, "Found wrong one"); - if (gr->glyph && gr->glyph != DeletedGlyph) { + if (gr && gr->glyph && gr->glyph != DeletedGlyph) { gr->glyph = DeletedGlyph; gr->signature = 0; globalGlyphs[format].tableEntries--; @@ -384,6 +388,7 @@ AllocateGlyph(xGlyphInfo * gi, int fdepth) static Bool AllocateGlyphHash(GlyphHashPtr hash, GlyphHashSetPtr hashSet) { + assert(hashSet); hash->table = calloc(hashSet->size, sizeof(GlyphRefRec)); if (!hash->table) return FALSE; @@ -418,10 +423,10 @@ ResizeGlyphHash(GlyphHashPtr hash, CARD32 change, Bool global) glyph = hash->table[i].glyph; if (glyph && glyph != DeletedGlyph) { s = hash->table[i].signature; - gr = FindGlyphRef(&newHash, s, global, glyph->sha1); - - gr->signature = s; - gr->glyph = glyph; + if ((gr = FindGlyphRef(&newHash, s, global, glyph->sha1))) { + gr->signature = s; + gr->glyph = glyph; + } ++newHash.tableEntries; } }