From 2fcbb8f256f515bec9b5db93743f281b00aba827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Thu, 10 Mar 2022 02:49:33 +0100 Subject: [PATCH] svgicons: Create initial icon painter before size detection. This resolve the potential crash during size detection. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko --- tdecore/svgicons/ksvgiconengine.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tdecore/svgicons/ksvgiconengine.cpp b/tdecore/svgicons/ksvgiconengine.cpp index 1a3004506..97e60fcb7 100644 --- a/tdecore/svgicons/ksvgiconengine.cpp +++ b/tdecore/svgicons/ksvgiconengine.cpp @@ -595,6 +595,10 @@ bool KSVGIconEngine::load(int width, int height, const TQString &path) // Detect width and height TQDomElement rootElement = rootNode.toElement(); + bool recreatePainter = false; + + // Create initial icon painter + d->painter = new KSVGIconPainter(width, height); d->width = width; // this sets default for no width -> 100% case if(rootElement.hasAttribute("width")) @@ -604,6 +608,7 @@ bool KSVGIconEngine::load(int width, int height, const TQString &path) if(!width) // no width set, use default { width = d->width; + recreatePainter = true; } } @@ -615,13 +620,16 @@ bool KSVGIconEngine::load(int width, int height, const TQString &path) if(!height) // no height set, use default { height = d->height; + recreatePainter = true; } } - // Create icon painter - d->painter = new KSVGIconPainter(width, height); - - // Create icon painter + // Create final icon painter + if(recreatePainter) + { + delete d->painter; + d->painter = new KSVGIconPainter(width, height); + } d->painter->setDrawWidth(static_cast(d->width)); d->painter->setDrawHeight(static_cast(d->height));