[Libreoffice-commits] core.git: filter/source include/filter oox/source sd/source sw/source

2018-07-10 Thread Armin Le Grand
 filter/source/msfilter/escherex.cxx   |  448 +++---
 filter/source/msfilter/eschesdo.cxx   |5 
 include/filter/msfilter/escherex.hxx  |   38 +-
 oox/source/export/vmlexport.cxx   |   45 ++-
 sd/source/filter/eppt/epptso.cxx  |   17 -
 sw/source/filter/ww8/rtfsdrexport.cxx |   12 
 sw/source/filter/ww8/wrtw8esh.cxx |   21 -
 7 files changed, 316 insertions(+), 270 deletions(-)

New commits:
commit b9bc45705bc3204c968fd6c902a1d5003c008023
Author: Armin Le Grand 
Date:   Fri Jul 6 15:16:06 2018 +0200

Make EscherPropertyContainer::CreatePolygonProperties safer

Additionally adapted EscherPropertyContainer's AddOpt
methods to be more safe and flexible. Added support for
SvMemoryStream. Changed Data handling in EscherPropSortStruct
to use std::vector, adapted all usages and
converions throgh all modules. This makes memorty handling
for these parts much safer (no more local new-ops, no
longer delete[] there).
Currently there are quite some usages of nProp.size() and
[0] to access the data. but the base for further
changes to work more on std::vector is done.

Change-Id: I982225c5bfc06fdd9e195d18cd3c550d15f1d48d
Reviewed-on: https://gerrit.libreoffice.org/57061
Tested-by: Jenkins
Reviewed-by: Armin Le Grand 

diff --git a/filter/source/msfilter/escherex.cxx 
b/filter/source/msfilter/escherex.cxx
index af43ad6b1903..775ebda731c9 100644
--- a/filter/source/msfilter/escherex.cxx
+++ b/filter/source/msfilter/escherex.cxx
@@ -169,39 +169,71 @@ EscherPropertyContainer::EscherPropertyContainer(
 
 EscherPropertyContainer::~EscherPropertyContainer()
 {
-if ( bHasComplexData )
+};
+
+void EscherPropertyContainer::AddOpt(
+sal_uInt16 nPropID,
+bool bBlib,
+sal_uInt32 nSizeReduction,
+SvMemoryStream& rStream)
+{
+sal_uInt8 const* pBuf(static_cast(rStream.GetData()));
+const sal_uInt64 nSize(rStream.GetSize());
+std::vector aBuf;
+aBuf.reserve(nSize);
+
+for(sal_uInt64 a(0); a < nSize; a++)
 {
-size_t nSortCount = pSortStruct.size();
-while ( nSortCount-- )
-delete[] pSortStruct[ nSortCount ].pBuf;
+aBuf.push_back(*pBuf++);
 }
-};
 
-void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, sal_uInt32 
nPropValue, bool bBlib )
+sal_uInt32 nPropValue(static_cast(nSize));
+
+if(0 != nSizeReduction && nPropValue > nSizeReduction)
+{
+nPropValue -= nSizeReduction;
+}
+
+AddOpt(nPropID, bBlib, nPropValue, aBuf);
+}
+
+void EscherPropertyContainer::AddOpt(
+sal_uInt16 nPropID,
+sal_uInt32 nPropValue,
+bool bBlib)
 {
-AddOpt( nPropID, bBlib, nPropValue, nullptr, 0 );
+AddOpt(nPropID, bBlib, nPropValue, std::vector());
 }
 
-void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, const OUString& 
rString )
+void EscherPropertyContainer::AddOpt(
+sal_uInt16 nPropID,
+const OUString& rString)
 {
-sal_Int32 j, i, nLen = rString.getLength() * 2 + 2;
-sal_uInt8* pBuf = new sal_uInt8[ nLen ];
-for ( j = i = 0; i < rString.getLength(); i++ )
+std::vector aBuf;
+aBuf.reserve(rString.getLength() * 2 + 2);
+
+for(sal_Int32 i(0); i < rString.getLength(); i++)
 {
-sal_uInt16 nChar = static_cast(rString[ i ]);
-pBuf[ j++ ] = static_cast(nChar);
-pBuf[ j++ ] = static_cast( nChar >> 8 );
+const sal_Unicode nUnicode(rString[i]);
+aBuf.push_back(static_cast(nUnicode));
+aBuf.push_back(static_cast(nUnicode >> 8));
 }
-pBuf[ j++ ] = 0;
-pBuf[ j++ ] = 0;
-AddOpt( nPropID, true, nLen, pBuf, nLen );
+
+aBuf.push_back(0);
+aBuf.push_back(0);
+
+AddOpt(nPropID, true, aBuf.size(), aBuf);
 }
 
-void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, bool bBlib, 
sal_uInt32 nPropValue, sal_uInt8* pProp, sal_uInt32 nPropSize )
+void EscherPropertyContainer::AddOpt(
+sal_uInt16 nPropID,
+bool bBlib,
+sal_uInt32 nPropValue,
+const std::vector& rProp)
 {
 if ( bBlib )// bBlib is only valid when fComplex = 0
 nPropID |= 0x4000;
-if ( pProp )
+if ( !rProp.empty() )
 nPropID |= 0x8000;  // fComplex = sal_True;
 
 for( size_t i = 0; i < pSortStruct.size(); i++ )
@@ -209,16 +241,14 @@ void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, 
bool bBlib, sal_uInt32
 if ( ( pSortStruct[ i ].nPropId &~0xc000 ) == ( nPropID &~0xc000 ) )   
 // check, whether the Property only gets replaced
 {
 pSortStruct[ i ].nPropId = nPropID;
-if ( pSortStruct[ i ].pBuf )
+if ( !pSortStruct[ i ].nProp.empty() )
 {
-nCountSize -= pSortStruct[ i ].nPropSize;
-delete[] pSortStruct[ i ].pBuf;
+nCountSize -= pSortStruct[ i ].nProp.size();
 }
-pSortStruct[ i ].pBuf = pProp;
-pSortStruct[ i ].nPropSize = nPropSize;
+ 

[Libreoffice-commits] core.git: filter/source include/filter oox/source sd/source

2016-12-04 Thread Noel Grandin
 filter/source/msfilter/escherex.cxx  |6 +++---
 include/filter/msfilter/escherex.hxx |   18 --
 oox/source/export/vmlexport.cxx  |2 +-
 sd/source/filter/eppt/epptso.cxx |2 +-
 4 files changed, 17 insertions(+), 11 deletions(-)

New commits:
commit d92d9df55c002323219012cd4896034e2be935fd
Author: Noel Grandin 
Date:   Fri Dec 2 16:10:09 2016 +0200

convert E_GRAPH_PROV constants to typed_flags

and drop the never checked
   E_GRAPH_PROV_DO_NOT_ROTATE_METAFILES
constant

Change-Id: Idd2598c209b34bfa4a58a84ce5ee14a7340d59d4
Reviewed-on: https://gerrit.libreoffice.org/31553
Tested-by: Jenkins 
Reviewed-by: Noel Grandin 

diff --git a/filter/source/msfilter/escherex.cxx 
b/filter/source/msfilter/escherex.cxx
index b6d5640..d6c8ce3 100644
--- a/filter/source/msfilter/escherex.cxx
+++ b/filter/source/msfilter/escherex.cxx
@@ -4065,7 +4065,7 @@ bool EscherBlibEntry::operator==( const EscherBlibEntry& 
rEscherBlibEntry ) cons
 return true;
 }
 
-EscherGraphicProvider::EscherGraphicProvider( sal_uInt32 nFlags ) :
+EscherGraphicProvider::EscherGraphicProvider( EscherGraphicProviderFlags 
nFlags ) :
 mnFlags ( nFlags ),
 mpBlibEntrys( nullptr ),
 mnBlibBufSize   ( 0 ),
@@ -4326,7 +4326,7 @@ sal_uInt32 EscherGraphicProvider::GetBlibID( SvStream& 
rPicOutStrm, const OStrin
 sal_uInt32 nExtra, nAtomSize = 0;
 sal_uInt32 nInstance, nUncompressedSize = 
p_EscherBlibEntry->mnSize;
 
-if ( mnFlags & E_GRAPH_PROV_USE_INSTANCES )
+if ( mnFlags & EscherGraphicProviderFlags::UseInstances )
 {
 rPicOutStrm.WriteUInt32( 0x7f9 | (sal_uInt16)( 
mnBlibEntrys << 4 ) )
.WriteUInt32( 0 );
@@ -4798,7 +4798,7 @@ void EscherSolverContainer::WriteSolver( SvStream& rStrm )
 }
 }
 
-EscherExGlobal::EscherExGlobal( sal_uInt32 nGraphicProvFlags ) :
+EscherExGlobal::EscherExGlobal( EscherGraphicProviderFlags nGraphicProvFlags ) 
:
 EscherGraphicProvider( nGraphicProvFlags ),
 mpPicStrm( nullptr ),
 mbHasDggCont( false ),
diff --git a/include/filter/msfilter/escherex.hxx 
b/include/filter/msfilter/escherex.hxx
index 00286c9..0e7a199 100644
--- a/include/filter/msfilter/escherex.hxx
+++ b/include/filter/msfilter/escherex.hxx
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace com { namespace sun { namespace star {
 namespace awt { struct Rectangle; }
@@ -545,13 +546,18 @@ public:
 };
 
 
-#define E_GRAPH_PROV_USE_INSTANCES 1
-#define E_GRAPH_PROV_DO_NOT_ROTATE_METAFILES   2
+enum class EscherGraphicProviderFlags {
+NONE= 0,
+UseInstances= 1,
+};
+namespace o3tl {
+template<> struct typed_flags : 
is_typed_flags {};
+}
 
 class MSFILTER_DLLPUBLIC EscherGraphicProvider
 {
-sal_uInt32  mnFlags;
-
+EscherGraphicProviderFlags
+mnFlags;
 EscherBlibEntry**   mpBlibEntrys;
 sal_uInt32  mnBlibBufSize;
 sal_uInt32  mnBlibEntrys;
@@ -585,7 +591,7 @@ public:
 voidSetBaseURI( const OUString& rBaseURI ) { maBaseURI = rBaseURI; 
};
 const OUString& GetBaseURI() { return maBaseURI; };
 
-EscherGraphicProvider( sal_uInt32 nFlags = 
E_GRAPH_PROV_DO_NOT_ROTATE_METAFILES );
+EscherGraphicProvider( EscherGraphicProviderFlags nFlags  = 
EscherGraphicProviderFlags::NONE );
 virtual ~EscherGraphicProvider();
 };
 
@@ -939,7 +945,7 @@ public:
 class MSFILTER_DLLPUBLIC EscherExGlobal : public EscherGraphicProvider
 {
 public:
-explicitEscherExGlobal( sal_uInt32 nGraphicProvFlags = 
E_GRAPH_PROV_DO_NOT_ROTATE_METAFILES );
+explicitEscherExGlobal( EscherGraphicProviderFlags 
nGraphicProvFlags = EscherGraphicProviderFlags::NONE );
 virtual ~EscherExGlobal() override;
 
 /** Returns a new drawing ID for a new drawing container (DGCONTAINER). */
diff --git a/oox/source/export/vmlexport.cxx b/oox/source/export/vmlexport.cxx
index 28de3dc..11035f2 100644
--- a/oox/source/export/vmlexport.cxx
+++ b/oox/source/export/vmlexport.cxx
@@ -52,7 +52,7 @@ static const sal_Int32 Tag_Container = 4;
 static const sal_Int32 Tag_Commit = 5;
 
 VMLExport::VMLExport( ::sax_fastparser::FSHelperPtr const & pSerializer, 
VMLTextExport* pTextExport )
-: EscherEx( std::make_shared(0), nullptr, /*bOOXML=*/true )
+: EscherEx( std::make_shared(), nullptr, /*bOOXML=*/true )
 , m_pSerializer( pSerializer )
 , m_pTextExport( pTextExport )
 , m_eHOri( 0 )
diff --git a/sd/source/filter/eppt/epptso.cxx b/sd/source/filter/eppt/epptso.cxx
index 3a320e1..3112e65 100644
--- a/sd/source/filter/eppt/epptso.cxx
+++ b/sd/source/filter/eppt/epptso.cxx
@@ -98,7 +98,7 @@ using namespace ::com::sun::star;