[Libreoffice-commits] .: sw/source
Caolán McNamara
caolan at kemper.freedesktop.org
Tue Jul 5 01:37:33 PDT 2011
sw/source/filter/ww8/WW8Sttbf.cxx | 37 +++++++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 8 deletions(-)
New commits:
commit 4aed88e86d8acb205582d3ba0df5134e221d855c
Author: Caolán McNamara <caolanm at redhat.com>
Date: Tue Jul 5 09:30:51 2011 +0100
fix endianness, drop interim copy, and clip to available size
diff --git a/sw/source/filter/ww8/WW8Sttbf.cxx b/sw/source/filter/ww8/WW8Sttbf.cxx
index c8f8b24..f8edb7f 100644
--- a/sw/source/filter/ww8/WW8Sttbf.cxx
+++ b/sw/source/filter/ww8/WW8Sttbf.cxx
@@ -30,6 +30,8 @@
#include <dbgoutsw.hxx>
#include "WW8Sttbf.hxx"
#include <cstdio>
+#include <osl/endian.h>
+#include <rtl/ustrbuf.hxx>
#if OSL_DEBUG_LEVEL > 1
#include <stdio.h>
@@ -75,12 +77,22 @@ namespace ww8
if (nCount > 0)
{
- rtl_uString * pNew = 0;
- rtl_uString_newFromStr_WithLength
- (&pNew, reinterpret_cast<const sal_Unicode *>(&mp_data[mn_offset + nOffset]),
- nCount);
-
- aResult = rtl::OUString(pNew);
+ //clip to available
+ sal_uInt32 nStartOff = mn_offset + nOffset;
+ if (nStartOff >= mn_size)
+ return aResult;
+ sal_uInt32 nAvailable = (mn_size - nStartOff)/sizeof(sal_Unicode);
+ if (nCount > nAvailable)
+ nCount = nAvailable;
+#if defined OSL_LITTLEENDIAN
+ aResult = rtl::OUString(reinterpret_cast<const sal_Unicode *>(
+ mp_data.get() + nStartOff), nCount);
+#else
+ rtl::OUStringBuffer aBuf;
+ for (sal_uInt32 i = 0; i < nCount; ++i)
+ aBuf.append(static_cast<sal_Unicode>(getU16(nStartOff+i*2)));
+ aResult = aBuf.makeStringAndClear();
+#endif
}
#if OSL_DEBUG_LEVEL > 1
@@ -103,8 +115,17 @@ namespace ww8
if (nCount > 0)
{
- ::rtl::OString aOStr(reinterpret_cast<const sal_Char *>(&mp_data[mn_offset + nOffset]),
- nCount);
+ //clip to available
+ sal_uInt32 nStartOff = mn_offset + nOffset;
+ if (nStartOff >= mn_size)
+ return aResult;
+ sal_uInt32 nAvailable = (mn_size - nStartOff);
+ if (nCount > nAvailable)
+ nCount = nAvailable;
+
+ rtl::OString aOStr(reinterpret_cast<const sal_Char *>(
+ mp_data.get() + nStartOff), nCount);
+
::rtl::OUString aOUStr(rtl::OStringToOUString(aOStr, RTL_TEXTENCODING_ASCII_US));
aResult = rtl::OUString(aOUStr);
}
More information about the Libreoffice-commits
mailing list