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>
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index a814f49..ca2800c 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;