[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang forms/source starmath/source vcl/source xmlhelp/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Aug 2 08:13:38 UTC 2018


 compilerplugins/clang/stringloop.cxx          |  123 +++++++++++++++++++++++++-
 forms/source/xforms/model_ui.cxx              |   15 +--
 starmath/source/ooxmlimport.cxx               |   97 ++++++++++----------
 vcl/source/filter/ipdf/pdfdocument.cxx        |   11 +-
 xmlhelp/source/cxxhelp/provider/databases.cxx |    4 
 5 files changed, 189 insertions(+), 61 deletions(-)

New commits:
commit e7a4426872429c2f286819cc0bdbc65fe4bd79cd
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Aug 1 19:25:27 2018 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Aug 2 10:13:23 2018 +0200

    forcepoint#66 make sure we don't get stuck endlessly reparsing
    
    Change-Id: Ie2733e8d7f73e5f6a072604c477e949cd944189a
    Reviewed-on: https://gerrit.libreoffice.org/58441
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx b/vcl/source/filter/ipdf/pdfdocument.cxx
index 3d9008a22943..c74bcbbade84 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -2212,9 +2212,14 @@ size_t PDFDictionaryElement::Parse(const std::vector<std::unique_ptr<PDFElement>
             else if (!pDictionary->alreadyParsing())
             {
                 // Nested dictionary.
-                i = PDFDictionaryElement::Parse(rElements, pDictionary, pDictionary->m_aItems);
-                rDictionary[aName] = pDictionary;
-                aName.clear();
+                const size_t nexti
+                    = PDFDictionaryElement::Parse(rElements, pDictionary, pDictionary->m_aItems);
+                if (nexti >= i) // ensure we go forwards and not endlessly loop
+                {
+                    i = nexti;
+                    rDictionary[aName] = pDictionary;
+                    aName.clear();
+                }
             }
         }
 
commit d5415561e3979d33b2a7e1a06e2d5515a1e1dd33
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Aug 2 08:59:42 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Aug 2 10:13:12 2018 +0200

    loplugin:stringloop in various
    
    Change-Id: Ia400e67108e622ae63a8d59667eae96c858f22dc
    Reviewed-on: https://gerrit.libreoffice.org/58463
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/stringloop.cxx b/compilerplugins/clang/stringloop.cxx
index 91cba802f3a6..31f1bfe08a37 100644
--- a/compilerplugins/clang/stringloop.cxx
+++ b/compilerplugins/clang/stringloop.cxx
@@ -39,6 +39,8 @@ private:
 
 void StringLoop::run()
 {
+    // Various places are not worth changing, the code becomes too awkward
+    // Just exclude stuff as I go
     StringRef fn(handler.getMainFileName());
     if (loplugin::hasPathnamePrefix(fn, SRCDIR "/bridges/"))
         return;
@@ -60,6 +62,120 @@ void StringLoop::run()
         return;
     if (loplugin::isSamePathname(fn, SRCDIR "/vcl/source/control/combobox.cxx"))
         return;
+    if (loplugin::isSamePathname(fn, SRCDIR "/vcl/source/gdi/pdfwriter_impl.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/svtools/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/idl/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/framework/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/basic/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sfx2/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/avmedia/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/connectivity/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/editeng/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/svx/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/basctl/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/filter/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/chart2/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/cui/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/dbaccess/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/oox/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/writerfilter/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/desktop/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/extensions/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/dtrans/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/i18npool/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/embeddedobj/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sd/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/xmloff/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/xmlhelp/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/forms/"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/core/tool/address.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/core/tool/compiler.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/ui/docshell/impex.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/ui/miscdlgs/acredlin.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/ui/pagedlg/areasdlg.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/ui/view/gridwin2.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/filter/html/htmlpars.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/doc/doctxm.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/edit/edattr.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/layout/dbg_lay.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/ascii/ascatr.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/html/htmlforw.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/unocore/unosect.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/unocore/unochart.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/unocore/unoobj.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/html/parcss1.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/html/svxcss1.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/html/swhtml.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/uibase/utlui/gloslst.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/uibase/utlui/content.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/uibase/docvw/edtwin.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/ww8/ww8atr.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/ww8/ww8scan.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/ww8/ww8par5.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/fldui/fldfunc.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/misc/bookmark.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/dbui/mmlayoutpage.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/dbui/dbinsdlg.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/dbui/mmresultdialogs.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/index/cnttab.cxx"))
+        return;
+    if (loplugin::hasPathnamePrefix(fn, SRCDIR "/ucb/source/ucp/file/bc.cxx"))
+        return;
 
     TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
 }
@@ -132,11 +248,16 @@ bool StringLoop::VisitCallExpr(CallExpr const* callExpr)
         if (!tc.Class("OUString").Namespace("rtl").GlobalNamespace()
             && !tc.Class("OString").Namespace("rtl").GlobalNamespace())
             return true;
+        auto fieldDecl = dyn_cast<FieldDecl>(memberExpr->getMemberDecl());
+        if (isInUnoIncludeFile(
+                compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocation())))
+            return true;
+        if (ignoreLocation(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocation())))
+            return true;
         report(DiagnosticsEngine::Warning,
                "appending to OUString in loop, rather use OUStringBuffer",
                operatorCallExpr->getLocStart())
             << operatorCallExpr->getSourceRange();
-        auto fieldDecl = dyn_cast<FieldDecl>(memberExpr->getMemberDecl());
         report(DiagnosticsEngine::Note, "field here", fieldDecl->getLocStart())
             << fieldDecl->getSourceRange();
     }
diff --git a/forms/source/xforms/model_ui.cxx b/forms/source/xforms/model_ui.cxx
index f6da0ce70803..ba3bbff52191 100644
--- a/forms/source/xforms/model_ui.cxx
+++ b/forms/source/xforms/model_ui.cxx
@@ -743,7 +743,7 @@ static OUString lcl_serializeForDisplay( const Reference< XAttr >& _rxAttrNode )
 
 static OUString lcl_serializeForDisplay( const Reference<XNodeList>& xNodes )
 {
-    OUString sResult;
+    OUStringBuffer sResult;
 
     // create document fragment
     Reference<XDocument> xDocument( getDocumentBuilder()->newDocument() );
@@ -770,7 +770,7 @@ static OUString lcl_serializeForDisplay( const Reference<XNodeList>& xNodes )
             Reference< XAttr > xAttr( xCurrent, UNO_QUERY );
             if ( xAttr.is() )
             {
-                sResult += lcl_serializeForDisplay( xAttr );
+                sResult.append(lcl_serializeForDisplay( xAttr ));
                 ++nAttributeNodes;
             }
         }
@@ -787,7 +787,7 @@ static OUString lcl_serializeForDisplay( const Reference<XNodeList>& xNodes )
         "lcl_serializeForDisplay: mixed attribute and non-attribute nodes?" );
     if ( nAttributeNodes )
         // had only attribute nodes
-        return sResult;
+        return sResult.makeStringAndClear();
 
     // serialize fragment
     CSerializationAppXML aSerialization;
@@ -808,20 +808,19 @@ static OUString lcl_serializeForDisplay( const Reference<XNodeList>& xNodes )
 
     // well, the serialization prepends XML header(s) that we need to
     // remove first.
-    OUStringBuffer aBuffer;
+    sResult.setLength(0);
     while( ! xTextInputStream->isEOF() )
     {
         OUString sLine = xTextInputStream->readLine();
         if( !sLine.isEmpty()
             && !sLine.startsWith( "<?xml" ) )
         {
-            aBuffer.append( sLine );
-            aBuffer.append( '\n' );
+            sResult.append( sLine );
+            sResult.append( '\n' );
         }
     }
-    sResult = aBuffer.makeStringAndClear();
 
-    return sResult;
+    return sResult.makeStringAndClear();
 }
 
 static OUString lcl_serializeForDisplay( const Reference<XXPathObject>& xResult )
diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index 7efa01d6740e..ca636f9138e6 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -47,7 +47,7 @@ OUString SmOoxmlImport::ConvertToStarMath()
 OUString SmOoxmlImport::handleStream()
 {
     m_rStream.ensureOpeningTag( M_TOKEN( oMath ));
-    OUString ret;
+    OUStringBuffer ret;
     while( !m_rStream.atEnd() && m_rStream.currentToken() != CLOSING( M_TOKEN( oMath )))
     {
         // strictly speaking, it is not OMathArg here, but currently supported
@@ -56,92 +56,92 @@ OUString SmOoxmlImport::handleStream()
         if( item.isEmpty())
             continue;
         if( !ret.isEmpty())
-            ret += " ";
-        ret += item;
+            ret.append(" ");
+        ret.append(item);
     }
     m_rStream.ensureClosingTag( M_TOKEN( oMath ));
     // Placeholders are written out as nothing (i.e. nothing inside e.g. the <e> element),
     // which will result in "{}" in the formula text. Fix this up.
-    ret = ret.replaceAll( "{}", "<?>" );
+    OUString ret2 = ret.makeStringAndClear().replaceAll( "{}", "<?>" );
     // And as a result, empty parts of the formula that are not placeholders are written out
     // as a single space, so fix that up too.
-    ret = ret.replaceAll( "{ }", "{}" );
-    SAL_INFO( "starmath.ooxml", "Formula: " << ret );
-    return ret;
+    ret2 = ret2.replaceAll( "{ }", "{}" );
+    SAL_INFO( "starmath.ooxml", "Formula: " << ret2 );
+    return ret2;
 }
 
 OUString SmOoxmlImport::readOMathArg( int stoptoken )
 {
-    OUString ret;
+    OUStringBuffer ret;
     while( !m_rStream.atEnd() && m_rStream.currentToken() != CLOSING( stoptoken ))
     {
         if( !ret.isEmpty())
-            ret += " ";
+            ret.append(" ");
         switch( m_rStream.currentToken())
         {
             case OPENING( M_TOKEN( acc )):
-                ret += handleAcc();
+                ret.append(handleAcc());
                 break;
             case OPENING( M_TOKEN( bar )):
-                ret += handleBar();
+                ret.append(handleBar());
                 break;
             case OPENING( M_TOKEN( box )):
-                ret += handleBox();
+                ret.append(handleBox());
                 break;
             case OPENING( M_TOKEN( borderBox )):
-                ret += handleBorderBox();
+                ret.append(handleBorderBox());
                 break;
             case OPENING( M_TOKEN( d )):
-                ret += handleD();
+                ret.append(handleD());
                 break;
             case OPENING( M_TOKEN( eqArr )):
-                ret += handleEqArr();
+                ret.append(handleEqArr());
                 break;
             case OPENING( M_TOKEN( f )):
-                ret += handleF();
+                ret.append(handleF());
                 break;
             case OPENING( M_TOKEN( func )):
-                ret += handleFunc();
+                ret.append(handleFunc());
                 break;
             case OPENING( M_TOKEN( limLow )):
-                ret += handleLimLowUpp( LimLow );
+                ret.append(handleLimLowUpp( LimLow ));
                 break;
             case OPENING( M_TOKEN( limUpp )):
-                ret += handleLimLowUpp( LimUpp );
+                ret.append(handleLimLowUpp( LimUpp ));
                 break;
             case OPENING( M_TOKEN( groupChr )):
-                ret += handleGroupChr();
+                ret.append(handleGroupChr());
                 break;
             case OPENING( M_TOKEN( m )):
-                ret += handleM();
+                ret.append(handleM());
                 break;
             case OPENING( M_TOKEN( nary )):
-                ret += handleNary();
+                ret.append(handleNary());
                 break;
             case OPENING( M_TOKEN( r )):
-                ret += handleR();
+                ret.append(handleR());
                 break;
             case OPENING( M_TOKEN( rad )):
-                ret += handleRad();
+                ret.append(handleRad());
                 break;
             case OPENING( M_TOKEN( sPre )):
-                ret += handleSpre();
+                ret.append(handleSpre());
                 break;
             case OPENING( M_TOKEN( sSub )):
-                ret += handleSsub();
+                ret.append(handleSsub());
                 break;
             case OPENING( M_TOKEN( sSubSup )):
-                ret += handleSsubsup();
+                ret.append(handleSsubsup());
                 break;
             case OPENING( M_TOKEN( sSup )):
-                ret += handleSsup();
+                ret.append(handleSsup());
                 break;
             default:
                 m_rStream.handleUnexpectedTag();
                 break;
         }
     }
-    return ret;
+    return ret.makeStringAndClear();
 }
 
 OUString SmOoxmlImport::readOMathArgInElement( int token )
@@ -364,17 +364,17 @@ OUString SmOoxmlImport::handleD()
 OUString SmOoxmlImport::handleEqArr()
 {
     m_rStream.ensureOpeningTag( M_TOKEN( eqArr ));
-    OUString ret;
+    OUStringBuffer ret;
     do
     { // there must be at least one m:e
         if( !ret.isEmpty())
-            ret += "#";
-        ret += " ";
-        ret += readOMathArgInElement( M_TOKEN( e ));
-        ret += " ";
+            ret.append("#");
+        ret.append(" ");
+        ret.append(readOMathArgInElement( M_TOKEN( e )));
+        ret.append(" ");
     } while( !m_rStream.atEnd() && m_rStream.findTag( OPENING( M_TOKEN( e ))));
     m_rStream.ensureClosingTag( M_TOKEN( eqArr ));
-    return "stack {" + ret + "}";
+    return "stack {" + ret.makeStringAndClear() + "}";
 }
 
 OUString SmOoxmlImport::handleF()
@@ -473,24 +473,24 @@ OUString SmOoxmlImport::handleGroupChr()
 OUString SmOoxmlImport::handleM()
 {
     m_rStream.ensureOpeningTag( M_TOKEN( m ));
-    OUString allrows;
+    OUStringBuffer allrows;
     do // there must be at least one m:mr
     {
         m_rStream.ensureOpeningTag( M_TOKEN( mr ));
-        OUString row;
+        OUStringBuffer row;
         do // there must be at least one m:e
         {
             if( !row.isEmpty())
-                row += " # ";
-            row += readOMathArgInElement( M_TOKEN( e ));
+                row.append(" # ");
+            row.append(readOMathArgInElement( M_TOKEN( e )));
         } while( !m_rStream.atEnd() && m_rStream.findTag( OPENING( M_TOKEN( e ))));
         if( !allrows.isEmpty())
-            allrows += " ## ";
-        allrows += row;
+            allrows.append(" ## ");
+        allrows.append(row);
         m_rStream.ensureClosingTag( M_TOKEN( mr ));
     } while( !m_rStream.atEnd() && m_rStream.findTag( OPENING( M_TOKEN( mr ))));
     m_rStream.ensureClosingTag( M_TOKEN( m ));
-    return "matrix {" + allrows + "}";
+    return "matrix {" + allrows.makeStringAndClear() + "}";
 }
 
 OUString SmOoxmlImport::handleNary()
@@ -584,7 +584,7 @@ OUString SmOoxmlImport::handleR()
         }
         m_rStream.ensureClosingTag( M_TOKEN( rPr ));
     }
-    OUString text;
+    OUStringBuffer text;
     while( !m_rStream.atEnd() && m_rStream.currentToken() != CLOSING( m_rStream.currentToken()))
     {
         switch( m_rStream.currentToken())
@@ -593,9 +593,9 @@ OUString SmOoxmlImport::handleR()
             {
                 XmlStream::Tag rtag = m_rStream.ensureOpeningTag( M_TOKEN( t ));
                 if( rtag.attribute( OOX_TOKEN( xml, space )) != "preserve" )
-                    text += rtag.text.trim();
+                    text.append(rtag.text.trim());
                 else
-                    text += rtag.text;
+                    text.append(rtag.text);
                 m_rStream.ensureClosingTag( M_TOKEN( t ));
                 break;
             }
@@ -606,8 +606,11 @@ OUString SmOoxmlImport::handleR()
     }
     m_rStream.ensureClosingTag( M_TOKEN( r ));
     if( normal || literal )
-        text = "\"" + text + "\"";
-    return text.replaceAll("{", "\\{").replaceAll("}", "\\}");
+    {
+        text.insert(0, "\"");
+        text.append("\"");
+    }
+    return text.makeStringAndClear().replaceAll("{", "\\{").replaceAll("}", "\\}");
 }
 
 OUString SmOoxmlImport::handleRad()
diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx
index 8f1694778a25..fa94f56a9a68 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.cxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.cxx
@@ -361,10 +361,10 @@ StaticModuleInformation* Databases::getStaticInformationForModule( const OUStrin
             sal_uInt64 nRead;
             sal_Char buffer[2048];
             sal_Unicode lineBuffer[1028];
-            OUString fileContent;
+            OUStringBuffer fileContent;
 
             while( osl::FileBase::E_None == cfgFile.read( &buffer,2048,nRead ) && nRead )
-                fileContent += OUString( buffer,sal_Int32( nRead ),RTL_TEXTENCODING_UTF8 );
+                fileContent.append(OUString( buffer,sal_Int32( nRead ),RTL_TEXTENCODING_UTF8 ));
 
             cfgFile.close();
 


More information about the Libreoffice-commits mailing list