Use known length to pre-initialize buffer

... and drop now-obsolete conditional include, which is included
unconditionally since commit 4c68c4b93c
  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>
This commit is contained in:
Mike Kaganski
2022-03-01 12:58:08 +03:00
parent 5028e5670d
commit 2960d41287
2 changed files with 6 additions and 9 deletions

View File

@@ -24,15 +24,12 @@
#include "WW8Sttbf.hxx" #include "WW8Sttbf.hxx"
#include <osl/endian.h> #include <osl/endian.h>
#include <o3tl/make_shared.hxx> #include <o3tl/make_shared.hxx>
#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#ifdef OSL_BIGENDIAN
#include <rtl/ustrbuf.hxx>
#endif
namespace ww8 namespace ww8
{ {
WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize) WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize)
@@ -71,7 +68,7 @@ namespace ww8
} }
OUString WW8Struct::getUString(sal_uInt32 nOffset, OUString WW8Struct::getUString(sal_uInt32 nOffset,
sal_uInt32 nCount) sal_Int32 nCount)
{ {
OUString aResult; OUString aResult;
@@ -82,10 +79,10 @@ namespace ww8
if (nStartOff >= mn_size) if (nStartOff >= mn_size)
return aResult; return aResult;
sal_uInt32 nAvailable = (mn_size - nStartOff)/sizeof(sal_Unicode); sal_uInt32 nAvailable = (mn_size - nStartOff)/sizeof(sal_Unicode);
if (nCount > nAvailable) if (o3tl::make_unsigned(nCount) > nAvailable)
nCount = nAvailable; nCount = nAvailable;
OUStringBuffer aBuf; OUStringBuffer aBuf(nCount);
for (sal_uInt32 i = 0; i < nCount; ++i) for (sal_Int32 i = 0; i < nCount; ++i)
aBuf.append(static_cast<sal_Unicode>(getU16(nStartOff+i*2))); aBuf.append(static_cast<sal_Unicode>(getU16(nStartOff+i*2)));
aResult = aBuf.makeStringAndClear(); aResult = aBuf.makeStringAndClear();
} }

View File

@@ -47,7 +47,7 @@ namespace ww8
sal_uInt16 getU16(sal_uInt32 nOffset) sal_uInt16 getU16(sal_uInt32 nOffset)
{ return getU8(nOffset) + (getU8(nOffset + 1) << 8); } { 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> template <class T>