summaryrefslogtreecommitdiff
path: root/include/tools
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-10-25 13:07:33 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-10-25 21:29:04 +0200
commit06533a4b9d2d249e2e16c6870de9ff29d590bb96 (patch)
treec30868e6c82345f22110e0a1289e783d60871847 /include/tools
parentd271ec87b8ec3264095a5265a7b0f1c073bc211b (diff)
ofz#3797 Integer-overflow
Change-Id: Iff545f441f2cf5e4f7626a6deff0ee0136c3af6b Reviewed-on: https://gerrit.libreoffice.org/43829 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include/tools')
-rw-r--r--include/tools/helpers.hxx9
1 files changed, 7 insertions, 2 deletions
diff --git a/include/tools/helpers.hxx b/include/tools/helpers.hxx
index 858ec4f7fc50..30064cf93fc6 100644
--- a/include/tools/helpers.hxx
+++ b/include/tools/helpers.hxx
@@ -10,6 +10,7 @@
#define INCLUDED_TOOLS_HELPERS_HXX
#include <sal/config.h>
+#include <sal/types.h>
#include <cassert>
#include <type_traits>
@@ -40,9 +41,13 @@ MinMax(T nVal, long nMin, long nMax)
: nMin);
}
-inline long AlignedWidth4Bytes( long nWidthBits )
+inline sal_uInt32 AlignedWidth4Bytes(sal_uInt32 nWidthBits)
{
- return ( ( nWidthBits + 31 ) >> 5 ) << 2;
+ if (nWidthBits > SAL_MAX_UINT32 - 31)
+ nWidthBits = SAL_MAX_UINT32;
+ else
+ nWidthBits += 31;
+ return (nWidthBits >> 5) << 2;
}
inline long FRound( double fVal )