diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2019-10-17 20:33:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-26 12:38:33 +0200 |
commit | e276c812648bf511d6c4813d6fd82a00391cfdac (patch) | |
tree | adbf24f41bef128a081cc1cc117c8023a3eed65d | |
parent | d04f044f05b4d13c3c6ea3f33fddd9c05a0ab3ad (diff) |
size some stringbuffer to prevent re-alloc
I started with 32 and kept doubling the size until the site
did not need re-alloc, but clamped it at 512 (e.g. in emfio/).
Change-Id: Ib7caf35a1b7e42b0e4ed8aa812493449e3eefc8f
Reviewed-on: https://gerrit.libreoffice.org/81540
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
26 files changed, 69 insertions, 51 deletions
diff --git a/basegfx/source/polygon/b2dsvgpolypolygon.cxx b/basegfx/source/polygon/b2dsvgpolypolygon.cxx index 991e50bf60f0..2fdacad3653f 100644 --- a/basegfx/source/polygon/b2dsvgpolypolygon.cxx +++ b/basegfx/source/polygon/b2dsvgpolypolygon.cxx @@ -722,7 +722,14 @@ namespace basegfx bool bOOXMLMotionPath) { const sal_uInt32 nCount(rPolyPolygon.count()); - OUStringBuffer aResult; + sal_uInt32 nCombinedPointCount = 0; + for(sal_uInt32 i(0); i < nCount; i++) + { + const B2DPolygon& aPolygon(rPolyPolygon.getB2DPolygon(i)); + nCombinedPointCount += aPolygon.count(); + } + + OUStringBuffer aResult(std::max<int>(nCombinedPointCount * 32,512)); B2DPoint aCurrentSVGPosition(0.0, 0.0); // SVG assumes (0,0) as the initial current point for(sal_uInt32 i(0); i < nCount; i++) diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx index f08c0178d38e..eee3764ab995 100644 --- a/basic/source/comp/scanner.cxx +++ b/basic/source/comp/scanner.cxx @@ -526,7 +526,7 @@ bool SbiScanner::NextSym() else aSym = aLine.copy( n, nCol - n - 1 ); // get out duplicate string delimiters - OUStringBuffer aSymBuf; + OUStringBuffer aSymBuf(aSym.getLength()); for ( sal_Int32 i = 0, len = aSym.getLength(); i < len; ++i ) { aSymBuf.append( aSym[i] ); diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index 2af16a5a712e..62016979049d 100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -1544,7 +1544,7 @@ void SbRtl_Join(StarBASIC *, SbxArray & rPar, bool) { aDelim = " "; } - OUStringBuffer aRetStr; + OUStringBuffer aRetStr(32); short nLower, nUpper; pArr->GetDim( 1, nLower, nUpper ); short aIdx[1]; diff --git a/basic/source/sbx/sbxcurr.cxx b/basic/source/sbx/sbxcurr.cxx index a1d274a0bdfd..b8df44d9fa26 100644 --- a/basic/source/sbx/sbxcurr.cxx +++ b/basic/source/sbx/sbxcurr.cxx @@ -35,7 +35,6 @@ static OUString ImpCurrencyToString( sal_Int64 rVal ) sal_Unicode const cDecimalSep = '.'; OUString aAbsStr = OUString::number( absVal ); - OUStringBuffer aBuf; sal_Int32 initialLen = aAbsStr.getLength(); @@ -53,6 +52,7 @@ static OUString ImpCurrencyToString( sal_Int64 rVal ) if ( isNeg ) ++nCapacity; + OUStringBuffer aBuf( nCapacity ); aBuf.setLength( nCapacity ); diff --git a/basic/source/sbx/sbxform.cxx b/basic/source/sbx/sbxform.cxx index 21ffa197a70e..c291f3e23af3 100644 --- a/basic/source/sbx/sbxform.cxx +++ b/basic/source/sbx/sbxform.cxx @@ -519,7 +519,7 @@ void SbxBasicFormater::ScanFormatString( double dNumber, nMultipleThousandSeparators; bool bPercent,bCurrency,bScientific,bGenerateThousandSeparator; - OUStringBuffer sReturnStrg; + OUStringBuffer sReturnStrg(32); // analyse the format-string, i. e. determine the following values: /* diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx index 1a03f16707d3..de76ecbba29d 100644 --- a/connectivity/source/drivers/hsqldb/HDriver.cxx +++ b/connectivity/source/drivers/hsqldb/HDriver.cxx @@ -142,12 +142,12 @@ namespace connectivity { OUString lcl_getPermittedJavaMethods_nothrow( const Reference< XComponentContext >& _rxContext ) { - OUStringBuffer aConfigPath; - aConfigPath.append( "/org.openoffice.Office.DataAccess/DriverSettings/" ); - aConfigPath.append ( ODriverDelegator::getImplementationName_Static() ); - aConfigPath.append( "/PermittedJavaMethods" ); + OUString aConfigPath = + "/org.openoffice.Office.DataAccess/DriverSettings/" + + ODriverDelegator::getImplementationName_Static() + + "/PermittedJavaMethods"; ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext( - _rxContext, aConfigPath.makeStringAndClear() ) ); + _rxContext, aConfigPath ) ); OUStringBuffer aPermittedMethods; const Sequence< OUString > aNodeNames( aConfig.getNodeNames() ); diff --git a/dbaccess/source/filter/hsqldb/createparser.cxx b/dbaccess/source/filter/hsqldb/createparser.cxx index 56f3f7fdb721..ad1c95f89966 100644 --- a/dbaccess/source/filter/hsqldb/createparser.cxx +++ b/dbaccess/source/filter/hsqldb/createparser.cxx @@ -52,14 +52,17 @@ std::vector<OUString> lcl_splitColumnPart(const OUString& sColumnPart) std::vector<OUString> sParts = string::split(sColumnPart, sal_Unicode(u',')); std::vector<OUString> sReturn; - OUStringBuffer current; + OUStringBuffer current(128); for (auto const& part : sParts) { current.append(part); if (current.lastIndexOf("(") > current.lastIndexOf(")")) current.append(","); // it was false split else - sReturn.push_back(current.makeStringAndClear()); + { + sReturn.push_back(current.toString()); + current.setLength(0); + } } return sReturn; } diff --git a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx index 756b2bd3d445..70b7810dc7c2 100644 --- a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx +++ b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx @@ -136,7 +136,8 @@ void FbCreateStmtParser::ensureProperTableLengths() const OUString FbCreateStmtParser::compose() const { ensureProperTableLengths(); - OUStringBuffer sSql("CREATE TABLE "); + OUStringBuffer sSql(128); + sSql.append("CREATE TABLE "); sSql.append(getTableName()); lcl_appendWithSpace(sSql, "("); // column declaration diff --git a/filter/source/graphicfilter/idxf/dxfgrprd.cxx b/filter/source/graphicfilter/idxf/dxfgrprd.cxx index 79520d18c655..1261f29823b0 100644 --- a/filter/source/graphicfilter/idxf/dxfgrprd.cxx +++ b/filter/source/graphicfilter/idxf/dxfgrprd.cxx @@ -34,7 +34,7 @@ static OString DXFReadLine(SvStream& rIStm) sal_uLong nOldFilePos = rIStm.Tell(); char c = 0; - OStringBuffer aBuf; + OStringBuffer aBuf(512); while( !bEnd && !rIStm.GetError() ) // !!! do not check for EOF // !!! because we read blockwise diff --git a/framework/source/uiconfiguration/CommandImageResolver.cxx b/framework/source/uiconfiguration/CommandImageResolver.cxx index c95ddeb56e76..3822f7eb2fa3 100644 --- a/framework/source/uiconfiguration/CommandImageResolver.cxx +++ b/framework/source/uiconfiguration/CommandImageResolver.cxx @@ -34,7 +34,7 @@ OUString lclConvertToCanonicalName(const OUString& rFileName) sal_Int32 nLength = rFileName.getLength(); const sal_Unicode* pString = rFileName.getStr(); - OUStringBuffer aBuffer(nLength); + OUStringBuffer aBuffer(nLength*2); for (sal_Int32 i = 0; i < nLength; i++) { diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx index 671713d48ffd..8ab74b652b64 100644 --- a/package/source/manifest/ManifestImport.hxx +++ b/package/source/manifest/ManifestImport.hxx @@ -55,7 +55,7 @@ class ManifestImport final : public cppu::WeakImplHelper < css::xml::sax::XDocum std::vector< css::beans::NamedValue > aKeyInfoSequence; std::vector< css::uno::Sequence< css::beans::NamedValue > > aKeys; std::vector< css::beans::PropertyValue > aSequence; - OUStringBuffer aCurrentCharacters; + OUStringBuffer aCurrentCharacters{64}; ManifestStack aStack; bool bIgnoreEncryptData; bool bPgpEncryption; diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx index c420da83120c..6a4c5570c877 100644 --- a/sc/inc/address.hxx +++ b/sc/inc/address.hxx @@ -964,14 +964,14 @@ SC_DLLPUBLIC void ScColToAlpha( OUStringBuffer& rBuffer, SCCOL nCol); inline void ScColToAlpha( OUString& rStr, SCCOL nCol) { - OUStringBuffer aBuf(2); + OUStringBuffer aBuf(4); ScColToAlpha( aBuf, nCol); rStr += aBuf; } inline OUString ScColToAlpha( SCCOL nCol ) { - OUStringBuffer aBuf(2); + OUStringBuffer aBuf(4); ScColToAlpha( aBuf, nCol); return aBuf.makeStringAndClear(); } diff --git a/sfx2/source/doc/DocumentMetadataAccess.cxx b/sfx2/source/doc/DocumentMetadataAccess.cxx index 5574bcada016..60862a0e887f 100644 --- a/sfx2/source/doc/DocumentMetadataAccess.cxx +++ b/sfx2/source/doc/DocumentMetadataAccess.cxx @@ -184,7 +184,7 @@ uno::Reference<rdf::XURI> createBaseURI( if (true) { xBaseURI.set( xPkgURI, uno::UNO_SET_THROW ); } - OUStringBuffer buf; + OUStringBuffer buf(64); if (!xBaseURI->getUriReference().endsWith("/")) { const sal_Int32 count( xBaseURI->getPathSegmentCount() ); diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx index b63fad9d529e..224d273fafb1 100644 --- a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx +++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx @@ -66,7 +66,7 @@ int parseEscaped(OUString const & part, sal_Int32 * index) { OUString parsePart( OUString const & part, bool namePart, sal_Int32 * index) { - OUStringBuffer buf; + OUStringBuffer buf(64); while (*index < part.getLength()) { sal_Unicode c = part[*index]; if (namePart ? c == '?' : c == '&' || c == '=') { diff --git a/svl/qa/unit/lockfiles/test_lockfiles.cxx b/svl/qa/unit/lockfiles/test_lockfiles.cxx index 5d2661ca00be..91920344d248 100644 --- a/svl/qa/unit/lockfiles/test_lockfiles.cxx +++ b/svl/qa/unit/lockfiles/test_lockfiles.cxx @@ -79,7 +79,7 @@ OUString readLockFile(const OUString& aSource) aFileStream.ReadBytes(pBuffer.get(), nSize); css::uno::Sequence<sal_Int8> aData(pBuffer.get(), nSize); - OStringBuffer aResult; + OStringBuffer aResult(static_cast<int>(nSize)); for (sal_Int8 nByte : aData) { aResult.append(static_cast<sal_Char>(nByte)); diff --git a/svl/source/misc/documentlockfile.cxx b/svl/source/misc/documentlockfile.cxx index bc3fe86ef819..935a568310fc 100644 --- a/svl/source/misc/documentlockfile.cxx +++ b/svl/source/misc/documentlockfile.cxx @@ -178,7 +178,7 @@ void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, const un { ::osl::MutexGuard aGuard( m_aMutex ); - OUStringBuffer aBuffer; + OUStringBuffer aBuffer(256); for ( LockFileComponent lft : o3tl::enumrange<LockFileComponent>() ) { diff --git a/svl/source/misc/lockfilecommon.cxx b/svl/source/misc/lockfilecommon.cxx index e27c1113d975..8daf3f3549b9 100644 --- a/svl/source/misc/lockfilecommon.cxx +++ b/svl/source/misc/lockfilecommon.cxx @@ -130,7 +130,7 @@ LockFileEntry LockFileCommon::ParseEntry( const uno::Sequence< sal_Int8 >& aBuff OUString LockFileCommon::ParseName( const uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& io_nCurPos ) { - OStringBuffer aResult; + OStringBuffer aResult(128); bool bHaveName = false; bool bEscape = false; @@ -168,7 +168,7 @@ OUString LockFileCommon::ParseName( const uno::Sequence< sal_Int8 >& aBuffer, sa OUString LockFileCommon::EscapeCharacters( const OUString& aSource ) { - OUStringBuffer aBuffer; + OUStringBuffer aBuffer(aSource.getLength()*2); const sal_Unicode* pStr = aSource.getStr(); for ( sal_Int32 nInd = 0; nInd < aSource.getLength() && pStr[nInd] != 0; nInd++ ) { diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 41db17082089..1f7db49ccec1 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -1647,7 +1647,7 @@ short SvNumberformat::ImpNextSymbol(OUStringBuffer& rString, sal_Unicode cLetter = ' '; // Preliminary result sal_Int32 nLen = rString.getLength(); ScanState eState = SsStart; - OUStringBuffer sBuffSymbol(32); + OUStringBuffer sBuffSymbol(64); const NfKeywordTable & rKeywords = rScan.GetKeywords(); while (nPos < nLen && eState != SsStop) @@ -2426,7 +2426,7 @@ bool SvNumberformat::GetOutputString(double fNumber, Color** ppColor) { bool bRes = false; - OUStringBuffer sBuff; + OUStringBuffer sBuff(64); OutString.clear(); *ppColor = nullptr; // No color change if (eType & SvNumFormatType::LOGICAL) @@ -5523,10 +5523,10 @@ void SvNumberformat::impTransliterateImpl(OUStringBuffer& rStr, { css::lang::Locale aLocale( LanguageTag( rNum.GetLang() ).getLocale() ); - OUString sTemp(rStr.makeStringAndClear()); + OUString sTemp(rStr.toString()); sTemp = GetFormatter().GetNatNum()->getNativeNumberStringParams( sTemp, aLocale, rNum.GetNatNum(), rNum.GetParams()); - rStr.append(sTemp); + rStr = sTemp; } OUString SvNumberformat::impTransliterateImpl(const OUString& rStr, diff --git a/tools/source/debug/debug.cxx b/tools/source/debug/debug.cxx index 4d4a817a7f40..3ab901c1aee9 100644 --- a/tools/source/debug/debug.cxx +++ b/tools/source/debug/debug.cxx @@ -406,7 +406,8 @@ OString exceptionToString(const css::uno::Any & caught) void DbgUnhandledException(const css::uno::Any & caught, const char* currentFunction, const char* fileAndLineNo, const char* area, const char* explanatory) { - OStringBuffer sMessage( "DBG_UNHANDLED_EXCEPTION in " ); + OStringBuffer sMessage( 512 ); + sMessage.append( "DBG_UNHANDLED_EXCEPTION in " ); sMessage.append(currentFunction); if (explanatory) { diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx index 39992a1834ca..636bfe42ff32 100644 --- a/tools/source/fsys/urlobj.cxx +++ b/tools/source/fsys/urlobj.cxx @@ -1449,7 +1449,8 @@ bool INetURLObject::setAbsURIRef(OUString const & rTheAbsURIRef, } void INetURLObject::changeScheme(INetProtocol eTargetScheme) { - OUString aTmpStr=m_aAbsURIRef.makeStringAndClear(); + OUString aTmpStr=m_aAbsURIRef.toString(); + m_aAbsURIRef.setLength(0); int oldSchemeLen = 0; if (m_eScheme == INetProtocol::Generic) oldSchemeLen = m_aScheme.getLength(); @@ -3365,7 +3366,7 @@ OUString INetURLObject::encodeText(sal_Unicode const * pBegin, rtl_TextEncoding eCharset, bool bKeepVisibleEscapes) { - OUStringBuffer aResult; + OUStringBuffer aResult(256); while (pBegin < pEnd) { EscapeType eEscapeType; @@ -4022,7 +4023,7 @@ bool INetURLObject::setName(OUString const& rTheName, EncodeMechanism eMechanism while (p != pSegEnd && *p != ';') ++p; - OUStringBuffer aNewPath; + OUStringBuffer aNewPath(256); aNewPath.append(pPathBegin, pSegBegin - pPathBegin); aNewPath.append(encodeText(rTheName, PART_PCHAR, eMechanism, eCharset, true)); aNewPath.append(p, pPathEnd - p); diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx index ed003e5d74e6..1e2ab5a237c5 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -894,12 +894,14 @@ namespace nTextLen = OUString(OUString::number(rFormatter.GetMin())).getLength(); string::padToLength(aBuf, nTextLen, '9'); Size aMinTextSize = rSpinField.CalcMinimumSizeForText( - rFormatter.CreateFieldText(aBuf.makeStringAndClear().toInt64())); + rFormatter.CreateFieldText(aBuf.toString().toInt64())); + aBuf.setLength(0); nTextLen = OUString(OUString::number(rFormatter.GetMax())).getLength(); string::padToLength(aBuf, nTextLen, '9'); Size aMaxTextSize = rSpinField.CalcMinimumSizeForText( - rFormatter.CreateFieldText(aBuf.makeStringAndClear().toInt64())); + rFormatter.CreateFieldText(aBuf.toString().toInt64())); + aBuf.setLength(0); Size aRet(std::max(aMinTextSize.Width(), aMaxTextSize.Width()), std::max(aMinTextSize.Height(), aMaxTextSize.Height())); diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx index b4a57c9c025e..22c61063bd21 100644 --- a/vcl/source/outdev/font.cxx +++ b/vcl/source/outdev/font.cxx @@ -1320,7 +1320,7 @@ std::unique_ptr<SalLayout> OutputDevice::ImplGlyphFallbackLayout( std::unique_pt // get list of code units that need glyph fallback int nCharPos = -1; bool bRTL = false; - OUStringBuffer aMissingCodeBuf; + OUStringBuffer aMissingCodeBuf(512); while (rLayoutArgs.GetNextPos( &nCharPos, &bRTL)) aMissingCodeBuf.append(rLayoutArgs.mrStr[nCharPos]); rLayoutArgs.ResetPos(); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index c396f7fb1787..f2873ecf97b8 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -1181,7 +1181,7 @@ RTFError RTFDocumentImpl::resolveChars(char ch) return RTFError::OK; } - OStringBuffer aBuf; + OStringBuffer aBuf(512); bool bUnicodeChecked = false; bool bSkipped = false; @@ -1275,8 +1275,9 @@ RTFError RTFDocumentImpl::resolveChars(char ch) return RTFError::OK; } - OUString aOUStr(OStringToOUString(aStr, m_aStates.top().getCurrentEncoding())); - SAL_INFO("writerfilter.rtf", "RTFDocumentImpl::resolveChars: collected '" << aOUStr << "'"); + SAL_INFO("writerfilter.rtf", + "RTFDocumentImpl::resolveChars: collected '" + << OStringToOUString(aStr, m_aStates.top().getCurrentEncoding()) << "'"); if (m_aStates.top().getDestination() == Destination::COLORTABLE) { @@ -2323,7 +2324,7 @@ RTFError RTFDocumentImpl::popState() { OUString aOrig = pValue->getString(); - OUStringBuffer aBuf; + OUStringBuffer aBuf(aOrig.getLength() * 2); sal_Int32 nReplaces = 1; for (int i = 0; i < aOrig.getLength(); i++) { @@ -2337,7 +2338,7 @@ RTFError RTFDocumentImpl::popState() - aState.getLevelNumbers().size())); } else - aBuf.append(std::u16string_view(aOrig).substr(i, 1)); + aBuf.append(aOrig[i]); } pValue->setString(aBuf.makeStringAndClear()); @@ -3566,7 +3567,8 @@ void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex) { if (bUnicode && !m_aUnicodeBuffer.isEmpty()) { - OUString aString = m_aUnicodeBuffer.makeStringAndClear(); + OUString aString = m_aUnicodeBuffer.toString(); + m_aUnicodeBuffer.setLength(0); text(aString); } if (bHex && !m_aHexBuffer.isEmpty()) @@ -3575,7 +3577,8 @@ void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex) if (m_aStates.top().getDestination() == Destination::FONTENTRY && m_aStates.top().getCurrentEncoding() == RTL_TEXTENCODING_SYMBOL) nEncoding = RTL_TEXTENCODING_MS_1252; - OUString aString = OStringToOUString(m_aHexBuffer.makeStringAndClear(), nEncoding); + OUString aString = OStringToOUString(m_aHexBuffer.toString(), nEncoding); + m_aHexBuffer.setLength(0); text(aString); } } diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 5ee84d791e5c..360c753172b7 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -590,7 +590,7 @@ private: sal_uInt16 m_nMinute; /// Text from special destinations. - OUStringBuffer m_aDestinationText; + OUStringBuffer m_aDestinationText{ 512 }; /// point to the buffer of the current destination OUStringBuffer* m_pCurrentDestinationText; @@ -931,9 +931,9 @@ private: /// For the INCLUDEPICTURE field's argument. OUString m_aPicturePath; // Unicode characters are collected here so we don't have to send them one by one. - OUStringBuffer m_aUnicodeBuffer; + OUStringBuffer m_aUnicodeBuffer{ 512 }; /// Same for hex characters. - OStringBuffer m_aHexBuffer; + OStringBuffer m_aHexBuffer{ 512 }; /// Formula import. oox::formulaimport::XmlStreamBuilder m_aMathBuffer; /// Normal text property, that is math italic and math spacing are not applied to the current run. diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx index 03d5d0d3e56a..0b39232cd983 100644 --- a/writerfilter/source/rtftok/rtftokenizer.cxx +++ b/writerfilter/source/rtftok/rtftokenizer.cxx @@ -182,7 +182,7 @@ void RTFTokenizer::popGroup() { m_nGroup--; } RTFError RTFTokenizer::resolveKeyword() { char ch; - OStringBuffer aBuf; + OStringBuffer aBuf(32); bool bNeg = false; bool bParam = false; int nParam = 0; @@ -202,6 +202,10 @@ RTFError RTFTokenizer::resolveKeyword() while (rtl::isAsciiAlpha(static_cast<unsigned char>(ch))) { aBuf.append(ch); + if (aBuf.getLength() > 32) + // See RTF spec v1.9.1, page 7 + // A control word's name cannot be longer than 32 letters. + throw io::BufferSizeExceededException(); Strm().ReadChar(ch); if (Strm().eof()) { @@ -209,10 +213,6 @@ RTFError RTFTokenizer::resolveKeyword() break; } } - if (aBuf.getLength() > 32) - // See RTF spec v1.9.1, page 7 - // A control word's name cannot be longer than 32 letters. - throw io::BufferSizeExceededException(); if (ch == '-') { diff --git a/xmlscript/source/xmlmod_imexp/imp_share.hxx b/xmlscript/source/xmlmod_imexp/imp_share.hxx index 31f2e86ff515..2a15f7d92d42 100644 --- a/xmlscript/source/xmlmod_imexp/imp_share.hxx +++ b/xmlscript/source/xmlmod_imexp/imp_share.hxx @@ -71,7 +71,7 @@ class ModuleElement OUString const _aLocalName; css::uno::Reference< css::xml::input::XAttributes > _xAttributes; - OUStringBuffer _strBuffer; + OUStringBuffer _strBuffer{512}; public: ModuleElement( |