summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2023-03-19 22:50:46 +0100
committerStephan Bergmann <sbergman@redhat.com>2023-03-20 07:01:25 +0000
commit926095df6b444866cd7e245b6a7befa6c2e29424 (patch)
tree9d9916ab8b1cba439a304ab020693ba18afa8f56 /sal
parent048d01ff0f0869be3b63ad62ea15e52f3727f617 (diff)
Shrink rtl_[u]String allocation size to what's actually needed
Change-Id: Ib39caf31b5d2fb06cc81cdeb14578794b35d8ed4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149120 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/strtmpl.hxx6
1 files changed, 4 insertions, 2 deletions
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index a814f4998a43..ca2800c6a012 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -22,6 +22,7 @@
#include <algorithm>
#include <cassert>
#include <cmath>
+#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <cwchar>
@@ -832,12 +833,13 @@ template <typename C> using STRINGDATA = typename STRINGDATA_<C>::T;
template <typename IMPL_RTL_STRINGDATA> IMPL_RTL_STRINGDATA* Alloc( sal_Int32 nLen )
{
+ constexpr auto fix = offsetof(IMPL_RTL_STRINGDATA, buffer) + sizeof IMPL_RTL_STRINGDATA::buffer;
IMPL_RTL_STRINGDATA * pData
= (sal::static_int_cast< sal_uInt32 >(nLen)
- <= ((SAL_MAX_UINT32 - sizeof (IMPL_RTL_STRINGDATA))
+ <= ((SAL_MAX_UINT32 - fix)
/ sizeof (STRCODE<IMPL_RTL_STRINGDATA>)))
? static_cast<IMPL_RTL_STRINGDATA *>(rtl_allocateString(
- sizeof (IMPL_RTL_STRINGDATA) + nLen * sizeof (STRCODE<IMPL_RTL_STRINGDATA>)))
+ fix + nLen * sizeof (STRCODE<IMPL_RTL_STRINGDATA>)))
: nullptr;
if (pData != nullptr) {
pData->refCount = 1;