lotuswordpro/source/filter/lwpobjstrm.cxx | 39 +++++++----------------------- lotuswordpro/source/filter/lwpobjstrm.hxx | 3 +- 2 files changed, 12 insertions(+), 30 deletions(-)
New commits: commit d18421575c7f1eb97d08cde6184c082e5ab828c3 Author: Caolán McNamara <caol...@redhat.com> Date: Tue Mar 14 12:03:59 2017 +0000 ofz: use std::vector for long buffers and set size of buffer to successfully read data for short reads Change-Id: I8d132446682104f2a4b8c476b7f2bda188bb3cdf diff --git a/lotuswordpro/source/filter/lwpobjstrm.cxx b/lotuswordpro/source/filter/lwpobjstrm.cxx index bc968a5..398a45d 100644 --- a/lotuswordpro/source/filter/lwpobjstrm.cxx +++ b/lotuswordpro/source/filter/lwpobjstrm.cxx @@ -71,24 +71,16 @@ LwpObjectStream::LwpObjectStream(LwpSvStream *pStrm, bool isCompressed, sal_uInt if (size >= IO_BUFFERSIZE) throw std::range_error("bad Object size"); // read object data from stream - if(m_nBufSize == 0) - { - m_pContentBuf = nullptr; - } - else - { + if (m_nBufSize > 0) Read2Buffer(); - } } + /** * @descr read object data from stream to buffer */ void LwpObjectStream::Read2Buffer() { - if( m_pContentBuf ) - { - ReleaseBuffer(); - } + ReleaseBuffer(); m_nReadPos = 0; @@ -98,7 +90,7 @@ void LwpObjectStream::Read2Buffer() sal_uInt8* pCompressBuffer = xCompressBuf.get(); memset(pCompressBuffer, 0, m_nBufSize); - m_pStrm->Read(pCompressBuffer, m_nBufSize); + m_nBufSize = m_pStrm->Read(pCompressBuffer, m_nBufSize); sal_uInt8 pTempDst[IO_BUFFERSIZE]; m_nBufSize = DecompressBuffer(pTempDst, pCompressBuffer, m_nBufSize); @@ -106,13 +98,11 @@ void LwpObjectStream::Read2Buffer() m_pContentBuf = AllocBuffer(m_nBufSize); memcpy(m_pContentBuf, pTempDst, m_nBufSize); - //delete [] pTempDst; - } else { m_pContentBuf = AllocBuffer(m_nBufSize); - m_pStrm->Read(m_pContentBuf, m_nBufSize); + m_nBufSize = m_pStrm->Read(m_pContentBuf, m_nBufSize); } } /** @@ -120,14 +110,12 @@ void LwpObjectStream::Read2Buffer() */ sal_uInt8* LwpObjectStream::AllocBuffer(sal_uInt16 size) { - if(size<=100) + if (size<=100) { return m_SmallBuffer; } - else - { - return new sal_uInt8[size]; - } + m_BigBuffer.resize(size); + return m_BigBuffer.data(); } /** * @descr signal complete to release object buffer @@ -146,15 +134,8 @@ LwpObjectStream::~LwpObjectStream() */ void LwpObjectStream::ReleaseBuffer() { - - if(m_nBufSize>100) - { - if(m_pContentBuf) - { - delete [] m_pContentBuf; - m_pContentBuf = nullptr; - } - } + m_BigBuffer.clear(); + m_pContentBuf = nullptr; } sal_uInt16 LwpObjectStream::remainingSize() const diff --git a/lotuswordpro/source/filter/lwpobjstrm.hxx b/lotuswordpro/source/filter/lwpobjstrm.hxx index 83062ee..28efe29 100644 --- a/lotuswordpro/source/filter/lwpobjstrm.hxx +++ b/lotuswordpro/source/filter/lwpobjstrm.hxx @@ -76,11 +76,12 @@ public: private: sal_uInt8* m_pContentBuf; //The content buffer of the object sal_uInt8 m_SmallBuffer[100]; //To avoid frequent new + std::vector<sal_uInt8> m_BigBuffer; //otherwise use this enum { IO_BUFFERSIZE = 0xFF00 //Refer to LWP, not sure if it is enough }; - sal_uInt16 m_nBufSize; //The total size of m_pContentBuf + sal_uInt16 m_nBufSize; //The total size of m_pContentBuf sal_uInt16 m_nReadPos; //The position of the quick read LwpSvStream* m_pStrm; bool m_bCompressed;
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits