summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-03-01 12:58:08 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-03-01 20:53:40 +0100
commit2960d4128710afd3e0c090960d281e69b44e69eb (patch)
treed86a60f7502e56d248482d8754be399111c05da6 /sw
parent5028e5670da25ec1e8eeee62789b744c32e6108b (diff)
Use known length to pre-initialize buffer
... and drop now-obsolete conditional include, which is included unconditionally since commit 4c68c4b93c41c4e9c2d5faf6c02ece2d40e95eb4 Author Stephan Bergmann <sbergman@redhat.com> Date Tue Mar 01 08:23:31 2022 +0100 misaligned-pointer-use Change nCount argument to sal_Int32, since that's what is used for string lengths. The call sites use sal_uInt16 and sal_uInt8 as the argument value. Change-Id: Ie2a9791f3ab9565590cb4f9c42d44f6eeff29745 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130754 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/filter/ww8/WW8Sttbf.cxx13
-rw-r--r--sw/source/filter/ww8/WW8Sttbf.hxx2
2 files changed, 6 insertions, 9 deletions
diff --git a/sw/source/filter/ww8/WW8Sttbf.cxx b/sw/source/filter/ww8/WW8Sttbf.cxx
index 2739f208d902..3143faece7dd 100644
--- a/sw/source/filter/ww8/WW8Sttbf.cxx
+++ b/sw/source/filter/ww8/WW8Sttbf.cxx
@@ -24,15 +24,12 @@
#include "WW8Sttbf.hxx"
#include <osl/endian.h>
#include <o3tl/make_shared.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <tools/stream.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
-#ifdef OSL_BIGENDIAN
-#include <rtl/ustrbuf.hxx>
-#endif
-
namespace ww8
{
WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize)
@@ -71,7 +68,7 @@ namespace ww8
}
OUString WW8Struct::getUString(sal_uInt32 nOffset,
- sal_uInt32 nCount)
+ sal_Int32 nCount)
{
OUString aResult;
@@ -82,10 +79,10 @@ namespace ww8
if (nStartOff >= mn_size)
return aResult;
sal_uInt32 nAvailable = (mn_size - nStartOff)/sizeof(sal_Unicode);
- if (nCount > nAvailable)
+ if (o3tl::make_unsigned(nCount) > nAvailable)
nCount = nAvailable;
- OUStringBuffer aBuf;
- for (sal_uInt32 i = 0; i < nCount; ++i)
+ OUStringBuffer aBuf(nCount);
+ for (sal_Int32 i = 0; i < nCount; ++i)
aBuf.append(static_cast<sal_Unicode>(getU16(nStartOff+i*2)));
aResult = aBuf.makeStringAndClear();
}
diff --git a/sw/source/filter/ww8/WW8Sttbf.hxx b/sw/source/filter/ww8/WW8Sttbf.hxx
index 89ec4113b308..3bc04e3d870b 100644
--- a/sw/source/filter/ww8/WW8Sttbf.hxx
+++ b/sw/source/filter/ww8/WW8Sttbf.hxx
@@ -47,7 +47,7 @@ namespace ww8
sal_uInt16 getU16(sal_uInt32 nOffset)
{ return getU8(nOffset) + (getU8(nOffset + 1) << 8); }
- OUString getUString(sal_uInt32 nOffset, sal_uInt32 nCount);
+ OUString getUString(sal_uInt32 nOffset, sal_Int32 nCount);
};
template <class T>