summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-08-15 01:20:43 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-09-10 02:12:37 +0200
commiteaab276fbb2939d6f315a9e491ff7925edfc6fd8 (patch)
tree1c4ed45eec528503eb046212ac75e1e968ab8692
parentf9386c07b1431aaa7cc091effe3b0e0847790731 (diff)
fix my horrible chunk header code
Change-Id: Ic91c06dbe05180d97b0db5de497f26f14b2d4ec4
-rw-r--r--include/oox/ole/vbaexport.hxx5
-rw-r--r--oox/source/ole/vbaexport.cxx50
2 files changed, 27 insertions, 28 deletions
diff --git a/include/oox/ole/vbaexport.hxx b/include/oox/ole/vbaexport.hxx
index 6993fe51284d..146bb88b5149 100644
--- a/include/oox/ole/vbaexport.hxx
+++ b/include/oox/ole/vbaexport.hxx
@@ -66,9 +66,6 @@ private:
// DecompressedEnd according to the spec
sal_uInt64 mnDecompressedEnd;
- // Start of the current decompressed chunk
- sal_uInt64 mnChunkStart;
-
void PackCompressedChunkSize(size_t nSize, sal_uInt16& rHeader);
void PackCompressedChunkFlag(bool bCompressed, sal_uInt16& rHeader);
@@ -89,6 +86,8 @@ private:
sal_uInt16& rBitCount, sal_uInt16& rMaximumLength);
void writeRawChunk();
+
+ sal_uInt16 handleHeader(bool bCompressed);
};
class VBACompression
diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index ea364bcdd082..723824be0b1a 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -55,13 +55,27 @@ VBACompressionChunk::VBACompressionChunk(SvStream& rCompressedStream, const sal_
{
}
+void setUInt16(sal_uInt8* pBuffer, size_t nPos, sal_uInt16 nVal)
+{
+ pBuffer[nPos] = nVal & 0xFF;
+ pBuffer[nPos+1] = (nVal & 0xFF00) >> 8;
+}
+
+sal_uInt16 VBACompressionChunk::handleHeader(bool bCompressed)
+{
+ // handle header bytes
+ size_t nSize = mnCompressedCurrent;
+ sal_uInt16 nHeader = 0;
+ PackCompressedChunkSize(nSize, nHeader);
+ PackCompressedChunkFlag(bCompressed, nHeader);
+ PackCompressedChunkSignature(nHeader);
+
+ return nHeader;
+}
+
// section 2.4.1.3.7
void VBACompressionChunk::write()
{
- mnChunkStart = mrCompressedStream.Tell();
-
- // we need to fill these two bytes later
- mrCompressedStream.WriteUInt16(0x0);
mnDecompressedCurrent = 0;
mnCompressedCurrent = 2;
@@ -80,30 +94,22 @@ void VBACompressionChunk::write()
compressTokenSequence();
}
- bool bCompressedFlag = true;
if (mnDecompressedCurrent < mnDecompressedEnd)
{
+ sal_uInt64 nChunkStart = mrCompressedStream.Tell();
+ mrCompressedStream.WriteUInt16(0);
writeRawChunk();
- bCompressedFlag = false;
+ mrCompressedStream.Seek(nChunkStart);
+ sal_uInt16 nHeader = handleHeader(false);
+ mrCompressedStream.WriteUInt16(nHeader);
}
else
{
+ sal_uInt16 nHeader = handleHeader(true);
+ setUInt16(pCompressedChunkStream, 0, nHeader);
// copy the compressed stream to our output stream
mrCompressedStream.Write(pCompressedChunkStream, mnCompressedCurrent);
}
-
- // handle header bytes
- size_t nSize = mnCompressedCurrent;
- sal_uInt16 nHeader = 0;
- PackCompressedChunkSize(nSize, nHeader);
- PackCompressedChunkFlag(bCompressedFlag, nHeader);
- PackCompressedChunkSignature(nHeader);
-
- // overwrite the two bytes
- sal_uInt64 nEnd = mrCompressedStream.Tell();
- mrCompressedStream.Seek(mnChunkStart);
- mrCompressedStream.WriteUInt16(nHeader);
- mrCompressedStream.Seek(nEnd);
}
// section 2.4.1.3.13
@@ -146,12 +152,6 @@ void VBACompressionChunk::compressTokenSequence()
mpCompressedChunkStream[nFlagByteIndex] = nFlagByte;
}
-void setUInt16(sal_uInt8* pBuffer, size_t nPos, sal_uInt16 nVal)
-{
- pBuffer[nPos] = nVal & 0xFFFF;
- pBuffer[nPos+1] = (nVal & 0xFFFF0000) >> 8;
-}
-
// section 2.4.1.3.9
void VBACompressionChunk::compressToken(size_t index, sal_uInt8& nFlagByte)
{