diff options
author | David Tardon <dtardon@redhat.com> | 2015-12-14 21:17:43 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2015-12-14 21:26:35 +0100 |
commit | c2fc9536a2734778351b7f2e712255c7df832037 (patch) | |
tree | c3d4e59aeb341c8ec816b7bb89f19662e08a13ae /oox | |
parent | ec41d544238616e968029ccabd72a01d6939f227 (diff) |
don't be creative and use a simple lookup table
The original code breaks at least in optimized build on Fedora x86,
because there nBits for 256 is computed as 9, not 8.
Change-Id: Ib157c415bc9e231bf7fd544349810e6bc83c8fcc
(cherry picked from commit fd94964ad6611d7f20523272fe6752d38e3aec88)
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/ole/vbaexport.cxx | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx index 2cb2fea90133..2041d50e1bef 100644 --- a/oox/source/ole/vbaexport.cxx +++ b/oox/source/ole/vbaexport.cxx @@ -9,6 +9,7 @@ #include <sal/config.h> +#include <cassert> #include <cmath> #include <random> @@ -324,8 +325,26 @@ void VBACompressionChunk::CopyTokenHelp(sal_uInt16& rLengthMask, sal_uInt16& rOf sal_uInt16& rBitCount, sal_uInt16& rMaximumLength) { sal_uInt16 nDifference = mnDecompressedCurrent; - sal_uInt16 nBitCount = std::ceil(std::log(nDifference)/std::log(2)); - rBitCount = std::max<sal_uInt16>(nBitCount, 4); + assert(nDifference <= 4096); + assert(nDifference >= 1); + if (nDifference >= 2049) + rBitCount = 12; + else if (nDifference >= 1025) + rBitCount = 11; + else if (nDifference >= 513) + rBitCount = 10; + else if (nDifference >= 257) + rBitCount = 9; + else if (nDifference >= 129) + rBitCount = 8; + else if (nDifference >= 65) + rBitCount = 7; + else if (nDifference >= 33) + rBitCount = 6; + else if (nDifference >= 17) + rBitCount = 5; + else + rBitCount = 4; rLengthMask = 0xffff >> rBitCount; rOffsetMask = ~rLengthMask; rMaximumLength = rLengthMask + 3; |