svx/source/xoutdev/_xpoly.cxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
New commits: commit d5af010a3287381db9accbf20063087ee18fcb62 Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Jan 24 11:09:42 2018 +0100 Allocate ImpXPolygon::pPointAry as a true Point[] ...as the default Point ctor already zero-initializes its members, remvoing the need for some memset calls (that cause -Werror=class-memaccess, "clearing an object of non-trivial type ‘class Point’" with upcoming GCC 8). Other such problematic memset calls are replaced with std::fill, which appears to produce adequate code with recent compilers (looked at GCC 7.2 and 8, Clang 7, at -O2), a tight loop of filling the memory with zeroes. A follow-up commit might want to use unique_ptr or vector for pPointAry. Change-Id: I566422b2213643ab762f0d87a25e745ec2f35ee4 Reviewed-on: https://gerrit.libreoffice.org/48488 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/svx/source/xoutdev/_xpoly.cxx b/svx/source/xoutdev/_xpoly.cxx index 4718a873228e..07ff1d214ec3 100644 --- a/svx/source/xoutdev/_xpoly.cxx +++ b/svx/source/xoutdev/_xpoly.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <algorithm> + #include <osl/endian.h> #include <tools/stream.hxx> #include <tools/debug.hxx> @@ -67,10 +71,10 @@ ImpXPolygon::ImpXPolygon( const ImpXPolygon& rImpXPoly ) ImpXPolygon::~ImpXPolygon() { - delete[] reinterpret_cast<char*>(pPointAry); + delete[] pPointAry; if ( bDeleteOldPoints ) { - delete[] reinterpret_cast<char*>(pOldPointAry); + delete[] pOldPointAry; pOldPointAry = nullptr; } } @@ -111,8 +115,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints ) } // create point array nSize = nNewSize; - pPointAry = reinterpret_cast<Point*>(new char[ nSize*sizeof( Point ) ]); - memset( pPointAry, 0, nSize*sizeof( Point ) ); + pPointAry = new Point[ nSize ]; // create flag array pFlagAry.reset( new PolyFlags[ nSize ] ); @@ -137,7 +140,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints ) } if ( bDeletePoints ) { - delete[] reinterpret_cast<char*>(pOldPointAry); + delete[] pOldPointAry; pOldPointAry = nullptr; } else @@ -165,7 +168,7 @@ void ImpXPolygon::InsertSpace( sal_uInt16 nPos, sal_uInt16 nCount ) nMove * sizeof(Point) ); memmove( &pFlagAry[nPos+nCount], &pFlagAry[nPos], nMove ); } - memset( &pPointAry[nPos], 0, nCount * sizeof( Point ) ); + std::fill(pPointAry + nPos, pPointAry + nPos + nCount, Point()); memset( &pFlagAry [nPos], 0, nCount ); nPoints = nPoints + nCount; @@ -185,7 +188,7 @@ void ImpXPolygon::Remove( sal_uInt16 nPos, sal_uInt16 nCount ) nMove * sizeof(Point) ); memmove( &pFlagAry[nPos], &pFlagAry[nPos+nCount], nMove ); } - memset( &pPointAry[nPoints - nCount], 0, nCount * sizeof( Point ) ); + std::fill(pPointAry + (nPoints - nCount), pPointAry + nPoints, Point()); memset( &pFlagAry [nPoints - nCount], 0, nCount ); nPoints = nPoints - nCount; } @@ -195,7 +198,7 @@ void ImpXPolygon::CheckPointDelete() const { if ( bDeleteOldPoints ) { - delete[] reinterpret_cast<char*>(pOldPointAry); + delete[] pOldPointAry; const_cast< ImpXPolygon* >(this)->pOldPointAry = nullptr; const_cast< ImpXPolygon* >(this)->bDeleteOldPoints = false; } @@ -344,7 +347,8 @@ void XPolygon::SetPointCount( sal_uInt16 nPoints ) if ( nPoints < pImpXPolygon->nPoints ) { sal_uInt16 nSize = pImpXPolygon->nPoints - nPoints; - memset( &pImpXPolygon->pPointAry[nPoints], 0, nSize * sizeof( Point ) ); + std::fill( + pImpXPolygon->pPointAry + nPoints, pImpXPolygon->pPointAry + nPoints + nSize, Point()); memset( &pImpXPolygon->pFlagAry [nPoints], 0, nSize ); } pImpXPolygon->nPoints = nPoints; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits