[Libreoffice-commits] core.git: 2 commits - basebmp/source basebmp/test include/basebmp

Thorsten Behrens tbehrens at suse.com
Tue Jun 4 11:40:55 PDT 2013


 basebmp/source/bitmapdevice.cxx  |   13 +++++++++----
 basebmp/source/debug.cxx         |    2 +-
 basebmp/test/bmptest.cxx         |   16 ++++++++++++++++
 include/basebmp/bitmapdevice.hxx |    3 +++
 4 files changed, 29 insertions(+), 5 deletions(-)

New commits:
commit 4dac6fe35573cfd59eb35e4323de1c16085d6a73
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Tue Jun 4 20:24:06 2013 +0200

    Add test for basebmp memory clobber.
    
    Cloned bitmap devices may share the same chunk of memory, thus
    risking overwriting our own data when we copy stuff around. Now
    caught from unit tests.
    
    Change-Id: I33b1a0b5d17550cbc6eced8bae01ae5ab9ebce9d

diff --git a/basebmp/source/debug.cxx b/basebmp/source/debug.cxx
index 4fe26f8..7650058 100644
--- a/basebmp/source/debug.cxx
+++ b/basebmp/source/debug.cxx
@@ -81,7 +81,7 @@ namespace basebmp
 
 #if OSL_DEBUG_LEVEL > 2
 
-    SAL_DLLPUBLIC_EXPORT void debugDump( const BitmapDeviceSharedPtr& rDevice,
+    void debugDump( const BitmapDeviceSharedPtr& rDevice,
                     std::ostream&                rOutputStream )
     {
         const basegfx::B2IVector aSize( rDevice->getSize() );
diff --git a/basebmp/test/bmptest.cxx b/basebmp/test/bmptest.cxx
index 571e32e..376b24f 100644
--- a/basebmp/test/bmptest.cxx
+++ b/basebmp/test/bmptest.cxx
@@ -89,6 +89,22 @@ private:
             DrawMode_PAINT );
         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
                                countPixel( rDevice, aCol ) == 32);
+
+        BitmapDeviceSharedPtr pClone = subsetBitmapDevice(
+            rBmp, aSourceRect );
+
+        // two overlapping areas within the same memory block, check
+        // if we clobber the mem or properly detect the case
+        const basegfx::B2IBox aSourceOverlap(0,0,6,10);
+        const basegfx::B2IBox aDestOverlap(3,0,9,10);
+        rBmp->drawBitmap(
+            pClone,
+            aSourceOverlap,
+            aDestOverlap,
+            DrawMode_PAINT );
+        CPPUNIT_ASSERT_MESSAGE("clobbertest - number of set pixel is not 50",
+                               countPixel( rBmp, aCol ) == 50);
+
     }
 
     void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice,
commit 31b35ed6bb7fe77f3f276b00fefce112a620b6ac
Author: Tsahi Glik <tsahi.glik at cloudon.com>
Date:   Tue Jun 4 20:25:41 2013 +0200

    Detect copyArea trying to operate on overlapping memory.
    
    Equality test also needs to check if disjunct BitmapDevice instances
    might not actually share the same memory buffer.
    
    Change-Id: I09a93cb092a0039353be211ed053e991e7fe66f0

diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx
index d1a19f9..ff017ec 100644
--- a/basebmp/source/bitmapdevice.cxx
+++ b/basebmp/source/bitmapdevice.cxx
@@ -680,7 +680,7 @@ namespace
                 destIterRange(begin,
                               acc,
                               rDstRect),
-                rSrcBitmap.get() == this );
+                isSharedBuffer(rSrcBitmap) );
             damaged( rDstRect );
         }
 
@@ -903,7 +903,7 @@ namespace
                                        Masks::clipmask_polarity,
                                        FastMask >::type(acc),
                               rDstRect),
-                rSrcBitmap.get() == this);
+                isSharedBuffer(rSrcBitmap));
             damaged( rDstRect );
         }
 
@@ -1147,6 +1147,11 @@ PaletteMemorySharedVector BitmapDevice::getPalette() const
     return mpImpl->mpPalette;
 }
 
+bool BitmapDevice::isSharedBuffer( const BitmapDeviceSharedPtr& rOther ) const
+{
+    return rOther.get()->getBuffer().get() == getBuffer().get();
+}
+
 void BitmapDevice::clear( Color fillColor )
 {
     clear_i( fillColor, mpImpl->maBounds );
@@ -1507,7 +1512,7 @@ void BitmapDevice::drawMaskedColor( Color                        aSrcColor,
         assertImagePoint(aDestPoint,mpImpl->maBounds);
         assertImageRange(aSrcRange,aSrcBounds);
 
-        if( rAlphaMask.get() == this )
+        if( isSharedBuffer(rAlphaMask) )
         {
             // src == dest, copy rAlphaMask beforehand
             // ---------------------------------------------------
@@ -1560,7 +1565,7 @@ void BitmapDevice::drawMaskedColor( Color                        aSrcColor,
 
         if( isCompatibleClipMask( rClip ) )
         {
-            if( rAlphaMask.get() == this )
+            if( isSharedBuffer(rAlphaMask) )
             {
                 // src == dest, copy rAlphaMask beforehand
                 // ---------------------------------------------------
diff --git a/include/basebmp/bitmapdevice.hxx b/include/basebmp/bitmapdevice.hxx
index 941b01c..84c6d75 100644
--- a/include/basebmp/bitmapdevice.hxx
+++ b/include/basebmp/bitmapdevice.hxx
@@ -140,6 +140,9 @@ public:
      */
     PaletteMemorySharedVector getPalette() const;
 
+    /// Check if this and the other BitmapDevice share a buffer
+    bool isSharedBuffer( const BitmapDeviceSharedPtr& rOther ) const;
+
     /** Clear whole device with given color
 
         This method works like a fill with the given color value,


More information about the Libreoffice-commits mailing list