include/vcl/BitmapConvolutionMatrixFilter.hxx       |   13 +++----------
 include/vcl/BitmapSharpenFilter.hxx                 |    6 +-----
 vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx |    9 ++++++++-
 3 files changed, 12 insertions(+), 16 deletions(-)

New commits:
commit 6122f6266c61db851d7595aeb824502172b509b2
Author: Noel Grandin <noel.gran...@collabora.co.uk>
Date:   Mon Apr 23 10:41:45 2018 +0200

    fix memory management in BitmapConvolutionMatrixFilter
    
    was deleting a stack allocated buffer.
    
    Also
    (*) drop the BitmapConvolutionMatrixFilter default constructor, the
    current code does not permit mpMatrix to be nullptr
    (*) declare the mpMatrix field as a reference to a fixed length array,
    to be more precise
    (*) pass the array in the constructor so that call sites will be
    properly type- and length-checked.
    
    Change-Id: I650d56cdfac0dae4ea77df7c0c03e19d658c00c8
    Reviewed-on: https://gerrit.libreoffice.org/53312
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/vcl/BitmapConvolutionMatrixFilter.hxx 
b/include/vcl/BitmapConvolutionMatrixFilter.hxx
index a2189326322b..cae8c3d8a91c 100644
--- a/include/vcl/BitmapConvolutionMatrixFilter.hxx
+++ b/include/vcl/BitmapConvolutionMatrixFilter.hxx
@@ -20,22 +20,15 @@ class BitmapEx;
 class VCL_DLLPUBLIC BitmapConvolutionMatrixFilter : public BitmapFilter
 {
 public:
-    BitmapConvolutionMatrixFilter()
-        : mpMatrix(nullptr)
+    BitmapConvolutionMatrixFilter(const long (&rMatrix)[9])
+        : mrMatrix(rMatrix)
     {
     }
 
-    BitmapConvolutionMatrixFilter(const long* pMatrix)
-        : mpMatrix(pMatrix)
-    {
-    }
-
-    ~BitmapConvolutionMatrixFilter() override { delete mpMatrix; }
-
     virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
 
 protected:
-    const long* mpMatrix;
+    const long (&mrMatrix)[9];
 };
 
 #endif
diff --git a/include/vcl/BitmapSharpenFilter.hxx 
b/include/vcl/BitmapSharpenFilter.hxx
index 7e965976d5e8..66cb56f3a1d5 100644
--- a/include/vcl/BitmapSharpenFilter.hxx
+++ b/include/vcl/BitmapSharpenFilter.hxx
@@ -16,11 +16,7 @@
 class VCL_DLLPUBLIC BitmapSharpenFilter : public BitmapConvolutionMatrixFilter
 {
 public:
-    BitmapSharpenFilter()
-    {
-        const long pSharpenMatrix[] = { -1, -1, -1, -1, 16, -1, -1, -1, -1 };
-        mpMatrix = &pSharpenMatrix[0];
-    }
+    BitmapSharpenFilter();
 };
 
 #endif
diff --git a/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx 
b/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx
index fea2e6dac4f4..bb1a1932c763 100644
--- a/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx
+++ b/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx
@@ -14,6 +14,7 @@
 #include <vcl/bitmapex.hxx>
 #include <vcl/bitmapaccess.hxx>
 #include <vcl/BitmapConvolutionMatrixFilter.hxx>
+#include <vcl/BitmapSharpenFilter.hxx>
 
 #include <bitmapwriteaccess.hxx>
 
@@ -53,7 +54,7 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx 
const& rBitmapEx)
             // create LUT of products of matrix value and possible color 
component values
             for (nY = 0; nY < 9; nY++)
             {
-                for (nX = nTmp = 0, nMatrixVal = mpMatrix[nY]; nX < 256; nX++, 
nTmp += nMatrixVal)
+                for (nX = nTmp = 0, nMatrixVal = mrMatrix[nY]; nX < 256; nX++, 
nTmp += nMatrixVal)
                 {
                     pKoeff[nY][nX] = nTmp;
                 }
@@ -196,4 +197,10 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx 
const& rBitmapEx)
     return BitmapEx();
 }
 
+static const long g_SharpenMatrix[] = { -1, -1, -1, -1, 16, -1, -1, -1, -1 };
+
+BitmapSharpenFilter::BitmapSharpenFilter()
+    : BitmapConvolutionMatrixFilter(g_SharpenMatrix)
+{
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to