From 68c72dfb9db5c452bad13203699b17c4f4fcf6cc Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Tue, 2 Apr 2013 16:16:12 +0200 Subject: Fix assertion in xmlparse and call this function with more care Plus change range to [nStart,nEnd). Change-Id: I1570d07fdc90a6b2bdf3eef7914958212cbbaa87 --- l10ntools/source/xmlparse.cxx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx index 651a27a5fd21..954aed0bc40c 100644 --- a/l10ntools/source/xmlparse.cxx +++ b/l10ntools/source/xmlparse.cxx @@ -1180,9 +1180,10 @@ static icu::UnicodeString lcl_QuotRange( const sal_Int32 nEnd, bool bInsideTag = false ) { icu::UnicodeString sReturn; + assert( nStart < nEnd ); assert( nStart >= 0 ); - assert( nEnd < rString.length() ); - for (sal_Int32 i = nStart; i <= nEnd; ++i) + assert( nEnd <= rString.length() ); + for (sal_Int32 i = nStart; i < nEnd; ++i) { switch (rString[i]) { @@ -1258,20 +1259,22 @@ OUString XMLUtil::QuotHTML( const OUString &rString ) while( aRegexMatcher.find(nStartPos, nIcuErr) && nIcuErr == U_ZERO_ERROR ) { nStartPos = aRegexMatcher.start(nIcuErr); - sReturn.append(lcl_QuotRange(sSource, nEndPos, nStartPos-1)); + if ( nEndPos < nStartPos ) + sReturn.append(lcl_QuotRange(sSource, nEndPos, nStartPos)); nEndPos = aRegexMatcher.end(nIcuErr); icu::UnicodeString sMatch = aRegexMatcher.group(nIcuErr); if( lcl_isTag(sMatch) ) { sReturn.append("<"); - sReturn.append(lcl_QuotRange(sSource, nStartPos+1, nEndPos-2, true)); + sReturn.append(lcl_QuotRange(sSource, nStartPos+1, nEndPos-1, true)); sReturn.append(">"); } else - sReturn.append(lcl_QuotRange(sSource, nStartPos, nEndPos-1)); + sReturn.append(lcl_QuotRange(sSource, nStartPos, nEndPos)); ++nStartPos; } - sReturn.append(lcl_QuotRange(sSource, nEndPos, sSource.length()-1)); + if( nEndPos < sSource.length() ) + sReturn.append(lcl_QuotRange(sSource, nEndPos, sSource.length())); sReturn.append('\0'); return OUString(reinterpret_cast(sReturn.getBuffer())); } -- cgit