So now UniString is gone we have the chance to make use of OUString for >= 64k paragraphs (#i17171#) but we basically have to decide what to do with places that currently return STRING_LEN/STRING_MAXLEN in xub_Strlen (unsigned short). Do we want to return -1 or SAL_MAX_INT32 as the replacement. -1 is "nice" but there is so much code in existence that expects the error/boundary condition return value to be > any valid number that I reckon SAL_MAX_INT32 might be safer as the default.
For a concrete place see OutputDevice::GetTextBreak where STRING_LEN is returned for the boundary case. See also grepping for STRING_LEN in sw and think mass search/replace STRING_LEN SAL_MAX_INT32 :-) For reference, I attach the trivial patches to remove the 16bit length limits in writer that stop anything larger that 0xFFFF entering it which are the final bits to be applied once everything else is done. C.
>From 00a379e51e629b218bcdd281e8be25f5f6cc3b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caol...@redhat.com> Date: Thu, 7 Nov 2013 14:59:33 +0000 Subject: [PATCH 01/12] Related: fdo#17171 stop clipping strings to STRING_LEN on .doc import Change-Id: Ic99132d0ee7804dc3625bef88cd35b2894f342c2 --- sw/source/filter/ww8/ww8par.cxx | 42 +++++++---------------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 6a1c048..66107ff 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -2974,19 +2974,13 @@ bool SwWW8ImplReader::ReadPlainChars(WW8_CP& rPos, sal_Int32 nEnd, sal_Int32 nCp // Reset Unicode flag and correct FilePos if needed. // Note: Seek is not expensive, as we're checking inline whether or not // the correct FilePos has already been reached. - xub_StrLen nStrLen; - if (nValidStrLen <= (STRING_MAXLEN-1)) - nStrLen = writer_cast<xub_StrLen>(nValidStrLen); - else - nStrLen = STRING_MAXLEN-1; - const rtl_TextEncoding eSrcCharSet = bVer67 ? GetCurrentCharSet() : RTL_TEXTENCODING_MS_1252; const rtl_TextEncoding eSrcCJKCharSet = bVer67 ? GetCurrentCJKCharSet() : RTL_TEXTENCODING_MS_1252; // allocate unicode string data - rtl_uString *pStr = rtl_uString_alloc(nStrLen); + rtl_uString *pStr = rtl_uString_alloc(nValidStrLen); sal_Unicode* pBuffer = pStr->buffer; sal_Unicode* pWork = pBuffer; @@ -2997,7 +2991,7 @@ bool SwWW8ImplReader::ReadPlainChars(WW8_CP& rPos, sal_Int32 nEnd, sal_Int32 nCp hConverter = rtl_createTextToUnicodeConverter(eSrcCharSet); if (!bIsUnicode) - p8Bits = new sal_Char[nStrLen]; + p8Bits = new sal_Char[nValidStrLen]; // read the stream data sal_uInt8 nBCode = 0; @@ -3009,7 +3003,7 @@ bool SwWW8ImplReader::ReadPlainChars(WW8_CP& rPos, sal_Int32 nEnd, sal_Int32 nCp if (pItem != NULL) nCTLLang = dynamic_cast<const SvxLanguageItem *>(pItem)->GetLanguage(); - for( nL2 = 0; nL2 < nStrLen; ++nL2, ++pWork ) + for( nL2 = 0; nL2 < nValidStrLen; ++nL2, ++pWork ) { if (bIsUnicode) *pStrm >> nUCode; // unicode --> read 2 bytes @@ -3064,9 +3058,9 @@ bool SwWW8ImplReader::ReadPlainChars(WW8_CP& rPos, sal_Int32 nEnd, sal_Int32 nCp xub_StrLen nEndUsed = nL2; if (!bIsUnicode) - nEndUsed = Custom8BitToUnicode(hConverter, p8Bits, nL2, pBuffer, nStrLen); + nEndUsed = Custom8BitToUnicode(hConverter, p8Bits, nL2, pBuffer, nValidStrLen); - for( sal_Int32 nI = 0; nI < nStrLen; ++nI, ++pBuffer ) + for( sal_Int32 nI = 0; nI < nValidStrLen; ++nI, ++pBuffer ) if (m_bRegardHindiDigits && bBidi && LangUsesHindiNumbers(nCTLLang)) *pBuffer = TranslateToHindiNumbers(*pBuffer); @@ -3085,7 +3079,7 @@ bool SwWW8ImplReader::ReadPlainChars(WW8_CP& rPos, sal_Int32 nEnd, sal_Int32 nCp if (pStr) rtl_uString_release(pStr); delete [] p8Bits; - return nL2 >= nStrLen; + return nL2 >= nValidStrLen; } #define MSASCII SAL_MAX_INT16 @@ -3326,29 +3320,7 @@ void SwWW8ImplReader::simpleAddTextToParagraph(const OUString& rAddString) if (!pNd) return; - if ((pNd->GetTxt().getLength() + rAddString.getLength()) < STRING_MAXLEN-1) - { - rDoc.InsertString(*pPaM, rAddString); - } - else - { - - if (pNd->GetTxt().getLength() < STRING_MAXLEN -1) - { - OUString sTempStr = rAddString.copy( 0, - STRING_MAXLEN - pNd->GetTxt().getLength() -1); - rDoc.InsertString(*pPaM, sTempStr); - sTempStr = rAddString.copy(sTempStr.getLength(), - rAddString.getLength() - sTempStr.getLength()); - AppendTxtNode(*pPaM->GetPoint()); - rDoc.InsertString(*pPaM, sTempStr); - } - else - { - AppendTxtNode(*pPaM->GetPoint()); - rDoc.InsertString(*pPaM, rAddString); - } - } + rDoc.InsertString(*pPaM, rAddString); bReadTable = false; } -- 1.8.3.1
>From 2d7e0999e188fa7cbf9a6c11023fdd56bc0655db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caol...@redhat.com> Date: Thu, 21 Nov 2013 09:28:22 +0000 Subject: [PATCH 02/12] Related: fdo#17171 stop clipping strings on insert/replace text Change-Id: Ie6f6ccab8675b2937e97138cc3214133fd754ad2 --- sw/inc/ndtxt.hxx | 10 +--------- sw/source/core/doc/docedt.cxx | 3 +-- sw/source/core/docnode/node.cxx | 23 ---------------------- sw/source/core/txtnode/ndtxt.cxx | 40 +++++++++------------------------------ sw/source/core/txtnode/txtedt.cxx | 10 ---------- 5 files changed, 11 insertions(+), 75 deletions(-) diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index d8e1fbb..2e8969e 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -69,11 +69,6 @@ namespace com { namespace sun { namespace star { typedef std::set< xub_StrLen > SwSoftPageBreakList; -// do not fill the String up to the max - need to be able to have a -// SwPosition "behind" the last character, i.e., at index TXTNODE_MAX + 1 -// (also STRING_LEN is often used for "not found") -const xub_StrLen TXTNODE_MAX = STRING_LEN - 2; - /// SwTxtNode is a paragraph in the document model. class SW_DLLPUBLIC SwTxtNode: public SwCntntNode, public ::sfx2::Metadatable { @@ -240,8 +235,7 @@ public: virtual sal_uInt16 ResetAllAttr(); /// insert text content - /// @param rStr text to insert; in case it does not fit into the limit of - /// TXTNODE_MAX, the longest prefix that fits is inserted + /// @param rStr text to insert /// @return the prefix of rStr that was actually inserted OUString InsertText( const OUString & rStr, const SwIndex & rIdx, const enum IDocumentContentOperations::InsertFlags nMode @@ -333,8 +327,6 @@ public: const SwIndex & rStart, const xub_StrLen nLen); /// replace nDelLen characters at rStart with rText - /// in case the replacement does not fit, it is partially inserted up to - /// TXTNODE_MAX void ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen, const OUString & rText ); void ReplaceTextOnly( xub_StrLen nPos, xub_StrLen nLen, diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx index 18f80ba..0ff9a55 100644 --- a/sw/source/core/doc/docedt.cxx +++ b/sw/source/core/doc/docedt.cxx @@ -713,8 +713,7 @@ bool SwDoc::Overwrite( const SwPaM &rRg, const OUString &rStr ) } SwTxtNode *pNode = rPt.nNode.GetNode().GetTxtNode(); - if (!pNode || ( static_cast<size_t>(rStr.getLength()) // worst case: no erase - + static_cast<size_t>(pNode->GetTxt().getLength()) > TXTNODE_MAX)) + if (!pNode) { return false; } diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index 6dee261..0cb7ae6 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -1579,21 +1579,6 @@ const SfxPoolItem* SwCntntNode::GetNoCondAttr( sal_uInt16 nWhich, return pFnd; } -static bool lcl_CheckMaxLength(SwNode const& rPrev, SwNode const& rNext) -{ - if (rPrev.GetNodeType() != rNext.GetNodeType()) - { - return false; - } - if (!rPrev.IsTxtNode()) - { - return true; - } - size_t const nSum(static_cast<const SwTxtNode&>(rPrev).GetTxt().getLength() - + static_cast<const SwTxtNode&>(rNext).GetTxt().getLength()); - return (nSum <= TXTNODE_MAX); -} - /// Can we join two Nodes? /// We can return the 2nd position in pIdx. int SwCntntNode::CanJoinNext( SwNodeIndex* pIdx ) const @@ -1609,10 +1594,6 @@ int SwCntntNode::CanJoinNext( SwNodeIndex* pIdx ) const if (rNds.Count()-1 == aIdx.GetIndex()) return sal_False; - if (!lcl_CheckMaxLength(*this, *pNd)) - { - return false; - } if( pIdx ) *pIdx = aIdx; return sal_True; @@ -1632,10 +1613,6 @@ int SwCntntNode::CanJoinPrev( SwNodeIndex* pIdx ) const if (0 == aIdx.GetIndex()) return sal_False; - if (!lcl_CheckMaxLength(*pNd, *this)) - { - return false; - } if( pIdx ) *pIdx = aIdx; return sal_True; diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 619e203..45d5dab 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -1797,18 +1797,7 @@ OUString SwTxtNode::InsertText( const OUString & rStr, const SwIndex & rIdx, const sal_Int32 aPos = rIdx.GetIndex(); sal_Int32 nLen = m_Text.getLength() - aPos; - sal_Int32 const nOverflow( - m_Text.getLength() + rStr.getLength() - TXTNODE_MAX); - SAL_WARN_IF(nOverflow > 0, "sw.core", - "SwTxtNode::InsertText: node text with insertion > TXTNODE_MAX."); - OUString const sInserted( - (nOverflow > 0) ? rStr.copy(0, rStr.getLength() - nOverflow) : rStr); - if (sInserted.isEmpty()) - { - return sInserted; - } - m_Text = m_Text.replaceAt(aPos, 0, sInserted); - assert(m_Text.getLength() <= TXTNODE_MAX); + m_Text = m_Text.replaceAt(aPos, 0, rStr); nLen = m_Text.getLength() - aPos - nLen; assert(nLen != 0); @@ -1909,7 +1898,7 @@ OUString SwTxtNode::InsertText( const OUString & rStr, const SwIndex & rIdx, SetCalcHiddenCharFlags(); CHECK_SWPHINTS(this); - return sInserted; + return rStr; } /************************************************************************* @@ -2089,11 +2078,6 @@ void SwTxtNode::CutImpl( SwTxtNode * const pDest, const SwIndex & rDestStart, pDest->m_Text = pDest->m_Text.replaceAt(nDestStart, 0, m_Text.copy(nTxtStartIdx, nLen)); m_Text = m_Text.replaceAt(nTxtStartIdx, nLen, ""); - if (m_Text.getLength() > TXTNODE_MAX) - { // FIXME: could only happen when called from SwRedline::Show. - // unfortunately can't really do anything here to handle that... - abort(); - } nLen = pDest->m_Text.getLength() - nInitSize; // update w/ current size! if( !nLen ) // String nicht gewachsen ?? return; @@ -3529,13 +3513,7 @@ void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen, assert( rStart.GetIndex() < m_Text.getLength() // index out of bounds && rStart.GetIndex() + nDelLen <= m_Text.getLength()); - long const nOverflow( - m_Text.getLength() + rStr.getLength() - nDelLen - TXTNODE_MAX); - SAL_WARN_IF(nOverflow > 0, "sw.core", - "SwTxtNode::ReplaceText: node text with insertion > TXTNODE_MAX."); - OUString const sInserted( - (nOverflow > 0) ? rStr.copy(0, rStr.getLength() - nOverflow) : rStr); - if (sInserted.isEmpty() && 0 == nDelLen) + if (rStr.isEmpty() && 0 == nDelLen) { return; // nothing to do } @@ -3565,17 +3543,17 @@ void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen, bool bOldExpFlg = IsIgnoreDontExpand(); SetIgnoreDontExpand( true ); - if (nLen && sInserted.getLength()) + if (nLen && rStr.getLength()) { // dann das 1. Zeichen ersetzen den Rest loschen und einfuegen // Dadurch wird die Attributierung des 1. Zeichen expandiert! - m_Text = m_Text.replaceAt(nStartPos, 1, sInserted.copy(0, 1)); + m_Text = m_Text.replaceAt(nStartPos, 1, rStr.copy(0, 1)); ++((SwIndex&)rStart); m_Text = m_Text.replaceAt(rStart.GetIndex(), nLen - 1, ""); Update( rStart, nLen - 1, true ); - OUString aTmpTxt( sInserted.copy(1) ); + OUString aTmpTxt( rStr.copy(1) ); m_Text = m_Text.replaceAt(rStart.GetIndex(), 0, aTmpTxt); Update( rStart, aTmpTxt.getLength(), false ); } @@ -3584,15 +3562,15 @@ void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen, m_Text = m_Text.replaceAt(nStartPos, nLen, ""); Update( rStart, nLen, true ); - m_Text = m_Text.replaceAt(nStartPos, 0, sInserted); - Update( rStart, sInserted.getLength(), false ); + m_Text = m_Text.replaceAt(nStartPos, 0, rStr); + Update( rStart, rStr.getLength(), false ); } SetIgnoreDontExpand( bOldExpFlg ); SwDelTxt aDelHint( nStartPos, nDelLen ); NotifyClients( 0, &aDelHint ); - SwInsTxt aHint( nStartPos, sInserted.getLength() ); + SwInsTxt aHint( nStartPos, rStr.getLength() ); NotifyClients( 0, &aHint ); } diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index e1eb5c3..214377b 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -1860,19 +1860,11 @@ void SwTxtNode::TransliterateText( { // now apply the changes from end to start to leave the offsets of the // yet unchanged text parts remain the same. - size_t nSum(m_Text.getLength()); for (size_t i = 0; i < aChanges.size(); ++i) { // check this here since AddChanges cannot be moved below // call to ReplaceTextOnly swTransliterationChgData & rData = aChanges[ aChanges.size() - 1 - i ]; - nSum = nSum + rData.sChanged.getLength() - rData.nLen; - if (nSum > TXTNODE_MAX) - { - SAL_WARN("sw.core", "SwTxtNode::ReplaceTextOnly: " - "node text with insertion > TXTNODE_MAX."); - return; - } if (pUndo) pUndo->AddChanges( *this, rData.nStart, rData.nLen, rData.aOffsets ); ReplaceTextOnly( rData.nStart, rData.nLen, rData.sChanged, rData.aOffsets ); @@ -1885,8 +1877,6 @@ void SwTxtNode::ReplaceTextOnly( xub_StrLen nPos, xub_StrLen nLen, const OUString & rText, const Sequence<sal_Int32>& rOffsets ) { - assert(m_Text.getLength() + rText.getLength() - nLen <= TXTNODE_MAX); - m_Text = m_Text.replaceAt(nPos, nLen, rText); sal_Int32 nTLen = rText.getLength(); -- 1.8.3.1
>From 193bc993775ad954ffdba4221d2ae45da27f19b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caol...@redhat.com> Date: Thu, 7 Nov 2013 15:01:15 +0000 Subject: [PATCH 03/12] Related: fdo#17171 stop clipping strings to STRING_LEN on .html import Change-Id: I77ec8f115eb23fa751016de1f6fa8caedf3d0d5b --- sw/source/filter/html/htmlcss1.cxx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx index ea8ea42..1fd8b89 100644 --- a/sw/source/filter/html/htmlcss1.cxx +++ b/sw/source/filter/html/htmlcss1.cxx @@ -1733,14 +1733,8 @@ sal_Bool SwHTMLParser::FileDownload( const OUString& rURL, aStream << *pStream; aStream.Seek( STREAM_SEEK_TO_END ); - OSL_ENSURE( aStream.Tell() < STRING_MAXLEN, - "File zu lang fuer einen String, Ende abgeschnitten" ); - xub_StrLen nLen = aStream.Tell() < STRING_MAXLEN - ? (xub_StrLen)aStream.Tell() - : STRING_MAXLEN; - - rStr = OUString( (const sal_Char *)aStream.GetData(), nLen - , GetSrcEncoding() ); + + rStr = OUString( (const sal_Char *)aStream.GetData(), aStream.Tell(), GetSrcEncoding() ); } -- 1.8.3.1
>From 6973d0866fb60e2708624e86c145ae2d86851ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caol...@redhat.com> Date: Thu, 7 Nov 2013 17:05:49 +0000 Subject: [PATCH 04/12] stop clipping string to STRING_LEN on glossary load Change-Id: Iaac046c659551156c159429cb181acd844761212 --- sw/source/core/edit/edglss.cxx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sw/source/core/edit/edglss.cxx b/sw/source/core/edit/edglss.cxx index c108035..9fc984d 100644 --- a/sw/source/core/edit/edglss.cxx +++ b/sw/source/core/edit/edglss.cxx @@ -315,11 +315,10 @@ sal_Bool SwEditShell::GetSelectedText( OUString &rBuf, int nHndlParaBrk ) xWrt->SetAsciiOptions( aAsciiOpt ); xWrt->bUCS2_WithStartChar = sal_False; - long lLen; - if( !IsError( aWriter.Write( xWrt ) ) && - STRING_MAXLEN > (( lLen = aStream.GetSize() ) - / sizeof( sal_Unicode )) + 1 ) + if( !IsError( aWriter.Write( xWrt ) ) ) { + long lLen = aStream.GetSize(); + aStream << (sal_Unicode)'\0'; const sal_Unicode *p = (sal_Unicode*)aStream.GetBuffer(); -- 1.8.3.1
>From 14cc1a96d1e5dc0eab13de382c018710e71fccfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caol...@redhat.com> Date: Thu, 7 Nov 2013 17:06:11 +0000 Subject: [PATCH 05/12] stop clipping string to STRING_LEN on autofmt load Change-Id: Ic0d1edbc3174d9da8b3df14bd9cd4cae22ca7ea1 --- sw/source/core/edit/autofmt.cxx | 2 -- 1 file changed, 2 deletions(-) diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx index 53a997e..8abf032 100644 --- a/sw/source/core/edit/autofmt.cxx +++ b/sw/source/core/edit/autofmt.cxx @@ -207,8 +207,6 @@ class SwAutoFormat !IsEmptyLine( *pTxtNd ) && !IsNoAlphaLine( *pTxtNd) && !IsEnumericChar( *pTxtNd ) && - ((STRING_MAXLEN - 50 - pTxtNd->GetTxt().getLength()) > - pAktTxtNd->GetTxt().getLength()) && !HasBreakAttr( *pTxtNd ); } -- 1.8.3.1
>From 81b6aa33bc047a3049d98b70445b70fc4fc86eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caol...@redhat.com> Date: Thu, 21 Nov 2013 09:43:43 +0000 Subject: [PATCH 08/12] longparas: drop overflow check Change-Id: I7333eced1d0e255f2a08cb23853bcd42c579b4b9 --- sw/source/core/doc/docedt.cxx | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx index d44fb0a..9089857 100644 --- a/sw/source/core/doc/docedt.cxx +++ b/sw/source/core/doc/docedt.cxx @@ -1220,26 +1220,6 @@ static std::vector<sal_uInt16> * lcl_RangesToVector(sal_uInt16 * pRanges) return pResult; } -static bool lcl_StrLenOverFlow( const SwPaM& rPam ) -{ - // If we try to merge two paragraph we have to test if afterwards - // the string doesn't exceed the allowed string length - bool bRet = false; - if( rPam.GetPoint()->nNode != rPam.GetMark()->nNode ) - { - const SwPosition* pStt = rPam.Start(), *pEnd = rPam.End(); - const SwTxtNode* pEndNd = pEnd->nNode.GetNode().GetTxtNode(); - if( (0 != pEndNd) && pStt->nNode.GetNode().IsTxtNode() ) - { - sal_uInt64 nSum = pStt->nContent.GetIndex() + - pEndNd->GetTxt().getLength() - pEnd->nContent.GetIndex(); - if( nSum > STRING_LEN ) - bRet = true; - } - } - return bRet; -} - void sw_GetJoinFlags( SwPaM& rPam, sal_Bool& rJoinTxt, sal_Bool& rJoinPrev ) { rJoinTxt = sal_False; @@ -1773,9 +1753,6 @@ bool SwDoc::DeleteRangeImplImpl(SwPaM & rPam) bool SwDoc::DeleteAndJoin( SwPaM & rPam, const bool bForceJoinNext ) { - if ( lcl_StrLenOverFlow( rPam ) ) - return false; - return lcl_DoWithBreaks( *this, rPam, (IsRedlineOn()) ? &SwDoc::DeleteAndJoinWithRedlineImpl : &SwDoc::DeleteAndJoinImpl, -- 1.8.3.1
_______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice