From 5db574727f4564238a54159a1a0673eaa2884b69 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 17 Jan 2022 21:47:48 +0100 Subject: [PATCH] Avoid -Werror=dangling-pointer= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > vcl/source/bitmap/Octree.cxx: In constructor ‘Octree::Octree(const BitmapReadAccess&, sal_uLong)’: > vcl/source/bitmap/Octree.cxx:69:17: error: storing the address of local variable ‘aColor’ in ‘*this.Octree::mpColor’ [-Werror=dangling-pointer=] > 69 | mpColor = &aColor; > | ~~~~~~~~^~~~~~~~~ > vcl/source/bitmap/Octree.cxx:67:21: note: ‘aColor’ declared here > 67 | BitmapColor aColor; > | ^~~~~~ > vcl/source/bitmap/Octree.cxx:67:21: note: ‘’ declared here (new with GCC 12) Change-Id: I5b1ffa15b92f2c41dbe51dfa843eb6bab3a4b449 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128517 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- vcl/inc/bitmap/Octree.hxx | 5 ++--- vcl/source/bitmap/Octree.cxx | 40 +++++++++++++++--------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/vcl/inc/bitmap/Octree.hxx b/vcl/inc/bitmap/Octree.hxx index 216f2fdd1875..4db06502256d 100644 --- a/vcl/inc/bitmap/Octree.hxx +++ b/vcl/inc/bitmap/Octree.hxx @@ -42,9 +42,9 @@ class VCL_PLUGIN_PUBLIC Octree { private: void CreatePalette(OctreeNode* pNode); - void GetPalIndex(const OctreeNode* pNode); + void GetPalIndex(const OctreeNode* pNode, BitmapColor const& color); - SAL_DLLPRIVATE void add(std::unique_ptr& rpNode); + SAL_DLLPRIVATE void add(std::unique_ptr& rpNode, BitmapColor const& color); SAL_DLLPRIVATE void reduce(); BitmapPalette maPalette; @@ -52,7 +52,6 @@ private: sal_uLong mnLevel; std::unique_ptr pTree; std::vector mpReduce; - BitmapColor const* mpColor; sal_uInt16 mnPalIndex; public: diff --git a/vcl/source/bitmap/Octree.cxx b/vcl/source/bitmap/Octree.cxx index fab0c8374ca8..98ad8c9fcf5d 100644 --- a/vcl/source/bitmap/Octree.cxx +++ b/vcl/source/bitmap/Octree.cxx @@ -34,7 +34,6 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) : mnLeafCount(0) , mnLevel(0) , mpReduce(OCTREE_BITS + 1, nullptr) - , mpColor(nullptr) , mnPalIndex(0) { const BitmapReadAccess* pAccess = &rReadAcc; @@ -53,9 +52,8 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) Scanline pScanline = pAccess->GetScanline(nY); for (tools::Long nX = 0; nX < nWidth; nX++) { - mpColor = &pAccess->GetPaletteColor(pAccess->GetIndexFromData(pScanline, nX)); mnLevel = 0; - add(pTree); + add(pTree, pAccess->GetPaletteColor(pAccess->GetIndexFromData(pScanline, nX))); while (mnLeafCount > nMax) reduce(); @@ -64,18 +62,13 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) } else { - BitmapColor aColor; - - mpColor = &aColor; - for (tools::Long nY = 0; nY < nHeight; nY++) { Scanline pScanline = pAccess->GetScanline(nY); for (tools::Long nX = 0; nX < nWidth; nX++) { - aColor = pAccess->GetPixelFromData(pScanline, nX); mnLevel = 0; - add(pTree); + add(pTree, pAccess->GetPixelFromData(pScanline, nX)); while (mnLeafCount > nMax) reduce(); @@ -86,7 +79,7 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) Octree::~Octree() {} -void Octree::add(std::unique_ptr& rpNode) +void Octree::add(std::unique_ptr& rpNode, BitmapColor const& color) { // possibly generate new nodes if (!rpNode) @@ -106,20 +99,20 @@ void Octree::add(std::unique_ptr& rpNode) if (rpNode->bLeaf) { rpNode->nCount++; - rpNode->nRed += mpColor->GetRed(); - rpNode->nGreen += mpColor->GetGreen(); - rpNode->nBlue += mpColor->GetBlue(); + rpNode->nRed += color.GetRed(); + rpNode->nGreen += color.GetGreen(); + rpNode->nBlue += color.GetBlue(); } else { const sal_uLong nShift = 7 - mnLevel; const sal_uInt8 cMask = 0x80 >> mnLevel; - const sal_uLong nIndex = (((mpColor->GetRed() & cMask) >> nShift) << 2) - | (((mpColor->GetGreen() & cMask) >> nShift) << 1) - | ((mpColor->GetBlue() & cMask) >> nShift); + const sal_uLong nIndex = (((color.GetRed() & cMask) >> nShift) << 2) + | (((color.GetGreen() & cMask) >> nShift) << 1) + | ((color.GetBlue() & cMask) >> nShift); mnLevel++; - add(rpNode->pChild[nIndex]); + add(rpNode->pChild[nIndex], color); } } @@ -184,7 +177,7 @@ void Octree::CreatePalette(OctreeNode* pNode) } } -void Octree::GetPalIndex(const OctreeNode* pNode) +void Octree::GetPalIndex(const OctreeNode* pNode, BitmapColor const& color) { if (pNode->bLeaf) mnPalIndex = pNode->nPalIndex; @@ -193,11 +186,11 @@ void Octree::GetPalIndex(const OctreeNode* pNode) const sal_uLong nShift = 7 - mnLevel; const sal_uInt8 cMask = 0x80 >> mnLevel; mnLevel++; - const sal_uLong nIndex = (((mpColor->GetRed() & cMask) >> nShift) << 2) - | (((mpColor->GetGreen() & cMask) >> nShift) << 1) - | ((mpColor->GetBlue() & cMask) >> nShift); + const sal_uLong nIndex = (((color.GetRed() & cMask) >> nShift) << 2) + | (((color.GetGreen() & cMask) >> nShift) << 1) + | ((color.GetBlue() & cMask) >> nShift); - GetPalIndex(pNode->pChild[nIndex].get()); + GetPalIndex(pNode->pChild[nIndex].get(), color); } } @@ -211,10 +204,9 @@ const BitmapPalette& Octree::GetPalette() sal_uInt16 Octree::GetBestPaletteIndex(const BitmapColor& rColor) { - mpColor = &rColor; mnPalIndex = 65535; mnLevel = 0; - GetPalIndex(pTree.get()); + GetPalIndex(pTree.get(), rColor); return mnPalIndex; }