diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-06-07 11:25:21 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-06-07 13:33:06 +0200 |
commit | eb1ec67d4e3f1992d7f31d824f06e48df8429540 (patch) | |
tree | 6399dc72de9032a24ca7be067e362beb5a35e1ea /sc | |
parent | 86828ea2e323eaba0b0cfa2da73089ee810caacf (diff) |
Avoid signed integer overflow
For whatever reason e5fe8434110c1299527a0d03bf450e1b6d08ca57 "use a SIMD
friendly hashcode for ScPatternAttr" had changed ScPatternAttr::mxHashCode from
sizt_t to sal_Int32, better use unsigned sal_uInt32 to avoid
> /sc/source/core/data/patattr.cxx:1444:17: runtime error: signed integer overflow: 31 * 887503681 cannot be represented in type 'int'
during e.g. CppunitTest_chart2_geometry
(<https://ci.libreoffice.org//job/lo_ubsan/2802/>)
Change-Id: Ia561b245431d812f43586013477208426aa1cc11
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152697
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/patattr.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/patattr.cxx | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx index 067193136fb9..49cae62994b4 100644 --- a/sc/inc/patattr.hxx +++ b/sc/inc/patattr.hxx @@ -53,7 +53,7 @@ enum ScAutoFontColorMode class SC_DLLPUBLIC ScPatternAttr final : public SfxSetItem { std::optional<OUString> pName; - mutable std::optional<sal_Int32> mxHashCode; + mutable std::optional<sal_uInt32> mxHashCode; ScStyleSheet* pStyle; sal_uInt64 mnKey; public: diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx index d2be666aa349..2b347365f0c2 100644 --- a/sc/source/core/data/patattr.cxx +++ b/sc/source/core/data/patattr.cxx @@ -1435,10 +1435,10 @@ void ScPatternAttr::CalcHashCode() const // This is an unrolled hash function so the compiler/CPU can execute it in parallel, // because we hit this hard when loading documents with lots of styles. // Set up seed so that an empty pattern does not have an (invalid) hash of 0. - sal_Int32 h1 = 1; - sal_Int32 h2 = 1; - sal_Int32 h3 = 1; - sal_Int32 h4 = 1; + sal_uInt32 h1 = 1; + sal_uInt32 h2 = 1; + sal_uInt32 h3 = 1; + sal_uInt32 h4 = 1; for (auto it = rSet.GetItems_Impl(), end = rSet.GetItems_Impl() + (compareSize / 4 * 4); it != end; ) { h1 = 31 * h1 + reinterpret_cast<size_t>(*it); |