drawinglayer/source/tools/emfphelperdata.cxx |   31 +++++++++++++++------------
 1 file changed, 18 insertions(+), 13 deletions(-)

New commits:
commit aa3daadddf5c39623ee1f69c2e96bc7cbc80a095
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Feb 28 09:45:55 2022 +0000
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Wed Mar 2 09:37:15 2022 +0100

    check if cast is to the right type
    
    LIBREOFFICE-311XVJ95
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130670
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit b44bd9ef8e2efdb66558917200e1f179b9db1c58)
    
    Change-Id: I159f516daafad3e4088677fe2c8c6f5423b3e264
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130810
    Tested-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/drawinglayer/source/tools/emfphelperdata.cxx 
b/drawinglayer/source/tools/emfphelperdata.cxx
index 69f9e33215a8..9ad9e1a78c26 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -346,7 +346,7 @@ namespace emfplushelper
         }
         else // we use a pen
         {
-            const EMFPPen* pen = 
static_cast<EMFPPen*>(maEMFPObjects[brushIndexOrColor & 0xff].get());
+            const EMFPPen* pen = 
dynamic_cast<EMFPPen*>(maEMFPObjects[brushIndexOrColor & 0xff].get());
             if (pen)
             {
                 color = pen->GetColor();
@@ -620,7 +620,7 @@ namespace emfplushelper
         }
         else // use Brush
         {
-            EMFPBrush* brush = static_cast<EMFPBrush*>( 
maEMFPObjects[brushIndexOrColor & 0xff].get() );
+            EMFPBrush* brush = dynamic_cast<EMFPBrush*>( 
maEMFPObjects[brushIndexOrColor & 0xff].get() );
             SAL_INFO("drawinglayer", "EMF+\t Fill polygon, brush slot: " << 
brushIndexOrColor << " (brush type: " << (brush ? brush->GetType() : -1) << 
")");
 
             // give up in case something wrong happened
@@ -1120,7 +1120,11 @@ namespace emfplushelper
                         rMS.ReadUInt32(brushIndexOrColor);
                         SAL_INFO("drawinglayer", "EMF+ FillRegion slot: " << 
index);
 
-                        
EMFPPlusFillPolygon(static_cast<EMFPRegion*>(maEMFPObjects[flags & 
0xff].get())->regionPolyPolygon, flags & 0x8000, brushIndexOrColor);
+                        EMFPRegion* region = 
dynamic_cast<EMFPRegion*>(maEMFPObjects[flags & 0xff].get());
+                        if (region)
+                            EMFPPlusFillPolygon(region->regionPolyPolygon, 
flags & 0x8000, brushIndexOrColor);
+                        else
+                            SAL_WARN("drawinglayer.emf", 
"EMF+\tEmfPlusRecordTypeFillRegion missing region");
                     }
                     break;
                     case EmfPlusRecordTypeDrawEllipse:
@@ -1295,9 +1299,10 @@ namespace emfplushelper
                         SAL_INFO("drawinglayer", "EMF+\tTODO: use image 
attributes");
 
                         // For DrawImage and DrawImagePoints, source unit of 
measurement type must be 1 pixel
-                        if (sourceUnit == UnitTypePixel && maEMFPObjects[flags 
& 0xff].get())
+                        if (EMFPImage* image = sourceUnit == UnitTypePixel ?
+                                dynamic_cast<EMFPImage*>(maEMFPObjects[flags & 
0xff].get()) :
+                                nullptr)
                         {
-                            EMFPImage& image = *static_cast<EMFPImage 
*>(maEMFPObjects[flags & 0xff].get());
                             float sx, sy, sw, sh;
                             ReadRectangle(rMS, sx, sy, sw, sh);
                             ::tools::Rectangle aSource(Point(sx, sy), Size(sw, 
sh));
@@ -1352,9 +1357,9 @@ namespace emfplushelper
                                         /* Row 1, Column 1 */ aDstSize.getY(),
                                         /* Row 1, Column 2 */ 
aDstPoint.getY());
 
-                            if (image.type == ImageDataTypeBitmap)
+                            if (image->type == ImageDataTypeBitmap)
                             {
-                                BitmapEx aBmp(image.graphic.GetBitmapEx());
+                                BitmapEx aBmp(image->graphic.GetBitmapEx());
                                 aBmp.Crop(aSource);
                                 Size aSize(aBmp.GetSizePixel());
                                 SAL_INFO("drawinglayer", "EMF+\t bitmap size: 
" << aSize.Width() << "x" << aSize.Height());
@@ -1369,9 +1374,9 @@ namespace emfplushelper
                                     break;
                                 }
                             }
-                            else if (image.type == ImageDataTypeMetafile)
+                            else if (image->type == ImageDataTypeMetafile)
                             {
-                                GDIMetaFile 
aGDI(image.graphic.GetGDIMetaFile());
+                                GDIMetaFile 
aGDI(image->graphic.GetGDIMetaFile());
                                 aGDI.Clip(aSource);
                                 mrTargetHolders.Current().append(
                                         
std::make_unique<drawinglayer::primitive2d::MetafilePrimitive2D>(aTransformMatrix,
 aGDI));
@@ -1405,7 +1410,7 @@ namespace emfplushelper
                             // get the stringFormat from the Object table ( 
this is OPTIONAL and may be nullptr )
                             const EMFPStringFormat *stringFormat = 
dynamic_cast<EMFPStringFormat*>(maEMFPObjects[formatId & 0xff].get());
                             // get the font from the flags
-                            const EMFPFont *font = static_cast< EMFPFont* >( 
maEMFPObjects[flags & 0xff].get() );
+                        const EMFPFont *font = 
dynamic_cast<EMFPFont*>(maEMFPObjects[flags & 0xff].get());
                             if (!font)
                             {
                                 break;
@@ -1770,7 +1775,7 @@ namespace emfplushelper
                         SAL_INFO("drawinglayer", "EMF+ SetClipPath combine 
mode: " << combineMode);
                         SAL_INFO("drawinglayer", "EMF+\tpath in slot: " << 
(flags & 0xff));
 
-                        EMFPPath *path = 
static_cast<EMFPPath*>(maEMFPObjects[flags & 0xff].get());
+                        EMFPPath *path = 
dynamic_cast<EMFPPath*>(maEMFPObjects[flags & 0xff].get());
                         if (!path)
                         {
                             SAL_WARN("drawinglayer", "EMF+\t TODO Unable to 
find path in slot: " << (flags & 0xff));
@@ -1787,7 +1792,7 @@ namespace emfplushelper
                         int combineMode = (flags >> 8) & 0xf;
                         SAL_INFO("drawinglayer", "EMF+ SetClipRegion");
                         SAL_INFO("drawinglayer", "EMF+\tregion in slot: " << 
(flags & 0xff) << " combine mode: " << combineMode);
-                        EMFPRegion *region = 
static_cast<EMFPRegion*>(maEMFPObjects[flags & 0xff].get());
+                        EMFPRegion *region = 
dynamic_cast<EMFPRegion*>(maEMFPObjects[flags & 0xff].get());
                         if (!region)
                         {
                             SAL_WARN("drawinglayer", "EMF+\t TODO Unable to 
find region in slot: " << (flags & 0xff));
@@ -1856,7 +1861,7 @@ namespace emfplushelper
                             }
 
                             // get the font from the flags
-                            EMFPFont *font = static_cast< EMFPFont* >( 
maEMFPObjects[flags & 0xff].get() );
+                            EMFPFont *font = 
dynamic_cast<EMFPFont*>(maEMFPObjects[flags & 0xff].get());
                             if (!font)
                             {
                                 break;

Reply via email to