[Libreoffice-commits] core.git: compilerplugins/clang include/oox oox/source sal/qa scripting/source sc/source

Stephan Bergmann sbergman at redhat.com
Fri Nov 25 15:43:16 UTC 2016


 compilerplugins/clang/stringconstant.cxx           |   72 ++++++++++-----------
 include/oox/ole/axfontdata.hxx                     |    3 
 oox/source/ole/axfontdata.cxx                      |    2 
 sal/qa/rtl/strings/test_oustring_compare.cxx       |    6 -
 sc/source/filter/oox/defnamesbuffer.cxx            |   10 +-
 sc/source/filter/oox/stylesbuffer.cxx              |    4 -
 scripting/source/protocolhandler/scripthandler.cxx |    8 --
 7 files changed, 47 insertions(+), 58 deletions(-)

New commits:
commit 1800862c700428e74aa500c9dee41237b8991932
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Nov 25 16:42:23 2016 +0100

    loplugin:stringconstant: look into 'char const * const var = "..."'
    
    Change-Id: I52a97b8ec273509131c2200e47527221cb62d7ee

diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index 9b9c934..6a04092 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -929,21 +929,17 @@ bool StringConstant::isStringConstant(
     // Look inside RTL_CONSTASCII_STRINGPARAM:
     if (loplugin::TypeCheck(t).Pointer().Const().Char()) {
         auto e2 = dyn_cast<UnaryOperator>(expr);
-        if (e2 == nullptr || e2->getOpcode() != UO_AddrOf) {
-            return false;
-        }
-        auto e3 = dyn_cast<ArraySubscriptExpr>(
-            e2->getSubExpr()->IgnoreParenImpCasts());
-        if (e3 == nullptr || !isZero(e3->getIdx()->IgnoreParenImpCasts())) {
-            return false;
+        if (e2 != nullptr && e2->getOpcode() == UO_AddrOf) {
+            auto e3 = dyn_cast<ArraySubscriptExpr>(
+                e2->getSubExpr()->IgnoreParenImpCasts());
+            if (e3 == nullptr || !isZero(e3->getIdx()->IgnoreParenImpCasts())) {
+                return false;
+            }
+            expr = e3->getBase()->IgnoreParenImpCasts();
+            t = expr->getType();
         }
-        expr = e3->getBase()->IgnoreParenImpCasts();
-        t = expr->getType();
     }
-    if (!(t->isConstantArrayType() && t.isConstQualified()
-          && (loplugin::TypeCheck(t->getAsArrayTypeUnsafe()->getElementType())
-              .Char())))
-    {
+    if (!t.isConstQualified()) {
         return false;
     }
     DeclRefExpr const * dre = dyn_cast<DeclRefExpr>(expr);
@@ -956,6 +952,14 @@ bool StringConstant::isStringConstant(
             }
         }
     }
+    if (!(loplugin::TypeCheck(t).Pointer().Const().Char()
+          || (t->isConstantArrayType()
+              && (loplugin::TypeCheck(
+                      t->getAsArrayTypeUnsafe()->getElementType())
+                  .Char()))))
+    {
+        return false;
+    }
     StringLiteral const * lit = dyn_cast<StringLiteral>(expr);
     if (lit != nullptr) {
         if (!lit->isAscii()) {
@@ -986,7 +990,9 @@ bool StringConstant::isStringConstant(
     case APValue::LValue:
         {
             Expr const * e = v.getLValueBase().dyn_cast<Expr const *>();
-            assert(e != nullptr); //TODO???
+            if (e == nullptr) {
+                return false;
+            }
             if (!v.getLValueOffset().isZero()) {
                 return false; //TODO
             }
@@ -1140,6 +1146,12 @@ void StringConstant::reportChange(
                                 << call->getSourceRange();
                             return;
                         }
+                        report(
+                            DiagnosticsEngine::Warning,
+                            "TODO call inside %0", getMemberLocation(expr))
+                            << fdecl->getQualifiedNameAsString()
+                            << expr->getSourceRange();
+                        return;
                     } else {
                         assert(pass == PassThrough::NonEmptyConstantString);
                         if ((dc.Function("equals").Class("OUString")
@@ -1160,29 +1172,17 @@ void StringConstant::reportChange(
                                 << expr->getSourceRange();
                             return;
                         }
-                        if ((dc.Operator(OO_Plus).Namespace("rtl")
-                             .GlobalNamespace())
-                            || (dc.Operator(OO_Plus).Class("OUString")
-                                .Namespace("rtl").GlobalNamespace()))
-                        {
-                            report(
-                                DiagnosticsEngine::Warning,
-                                ("rewrite call of " + original + " with "
-                                 + describeChangeKind(kind)
-                                 + (" in call of %0  as (implicit) construction"
-                                    " of rtl::OUString")),
-                                getMemberLocation(expr))
-                                << fdecl->getQualifiedNameAsString()
-                                << expr->getSourceRange();
-                            return;
-                        }
+                        report(
+                            DiagnosticsEngine::Warning,
+                            ("rewrite call of " + original + " with "
+                             + describeChangeKind(kind)
+                             + (" in call of %0 as (implicit) construction of"
+                                " rtl::OUString")),
+                            getMemberLocation(expr))
+                            << fdecl->getQualifiedNameAsString()
+                            << expr->getSourceRange();
+                        return;
                     }
-                    report(
-                        DiagnosticsEngine::Warning,
-                        "TODO call inside %0", getMemberLocation(expr))
-                        << fdecl->getQualifiedNameAsString()
-                        << expr->getSourceRange();
-                    return;
                 } else if (isa<CXXConstructExpr>(call)) {
                     auto cdecl = cast<CXXConstructExpr>(call)->getConstructor()
                         ->getParent();
diff --git a/include/oox/ole/axfontdata.hxx b/include/oox/ole/axfontdata.hxx
index b6bcf9e..3e01af4 100644
--- a/include/oox/ole/axfontdata.hxx
+++ b/include/oox/ole/axfontdata.hxx
@@ -32,9 +32,6 @@ namespace oox {
 namespace oox {
 namespace ole {
 
-
-const sal_Char* const AX_GUID_CFONT         = "{AFC20920-DA4E-11CE-B943-00AA006887B4}";
-
 const sal_uInt32 AX_FONTDATA_BOLD           = 0x00000001;
 const sal_uInt32 AX_FONTDATA_ITALIC         = 0x00000002;
 const sal_uInt32 AX_FONTDATA_UNDERLINE      = 0x00000004;
diff --git a/oox/source/ole/axfontdata.cxx b/oox/source/ole/axfontdata.cxx
index ea31b3d..549d807 100644
--- a/oox/source/ole/axfontdata.cxx
+++ b/oox/source/ole/axfontdata.cxx
@@ -102,7 +102,7 @@ bool AxFontData::importStdFont( BinaryInputStream& rInStrm )
 bool AxFontData::importGuidAndFont( BinaryInputStream& rInStrm )
 {
     OUString aGuid = OleHelper::importGuid( rInStrm );
-    if( aGuid.equalsAscii( AX_GUID_CFONT ) )
+    if( aGuid == "{AFC20920-DA4E-11CE-B943-00AA006887B4}" )
         return importBinaryModel( rInStrm );
     if ( aGuid == OLE_GUID_STDFONT )
         return importStdFont( rInStrm );
diff --git a/sal/qa/rtl/strings/test_oustring_compare.cxx b/sal/qa/rtl/strings/test_oustring_compare.cxx
index d500e5c..5a0b2cb 100644
--- a/sal/qa/rtl/strings/test_oustring_compare.cxx
+++ b/sal/qa/rtl/strings/test_oustring_compare.cxx
@@ -45,9 +45,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::Compare);
 
 void test::oustring::Compare::equalsIgnoreAsciiCaseAscii()
 {
-    const char* const abc = "abc";
-    const char* const abcd = "abcd";
-    const char* const empty = "";
+    const char* abc = "abc";
+    const char* abcd = "abcd";
+    const char* empty = "";
     CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAscii(abc));
     CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAsciiL(abc,3));
     CPPUNIT_ASSERT(!rtl::OUString("abc").
diff --git a/sc/source/filter/oox/defnamesbuffer.cxx b/sc/source/filter/oox/defnamesbuffer.cxx
index 79457ab..9bbaf53 100644
--- a/sc/source/filter/oox/defnamesbuffer.cxx
+++ b/sc/source/filter/oox/defnamesbuffer.cxx
@@ -59,7 +59,7 @@ const sal_uInt16 BIFF_REFFLAG_ROW1REL       = 0x0002;
 const sal_uInt16 BIFF_REFFLAG_COL2REL       = 0x0004;
 const sal_uInt16 BIFF_REFFLAG_ROW2REL       = 0x0008;
 
-const sal_Char* const spcOoxPrefix = "_xlnm.";
+const OUStringLiteral spcOoxPrefix("_xlnm.");
 
 const sal_Char* const sppcBaseNames[] =
 {
@@ -92,21 +92,19 @@ OUString lclGetBaseName( sal_Unicode cBuiltinId )
 
 OUString lclGetPrefixedName( sal_Unicode cBuiltinId )
 {
-    return OUStringBuffer().appendAscii( spcOoxPrefix ).append( lclGetBaseName( cBuiltinId ) ).makeStringAndClear();
+    return OUStringBuffer( spcOoxPrefix ).append( lclGetBaseName( cBuiltinId ) ).makeStringAndClear();
 }
 
 /** returns the built-in name identifier from a prefixed built-in name, e.g. '_xlnm.Print_Area'. */
 sal_Unicode lclGetBuiltinIdFromPrefixedName( const OUString& rModelName )
 {
-    OUString aPrefix = OUString::createFromAscii( spcOoxPrefix );
-    sal_Int32 nPrefixLen = aPrefix.getLength();
-    if( rModelName.matchIgnoreAsciiCase( aPrefix ) )
+    if( rModelName.matchIgnoreAsciiCase( spcOoxPrefix ) )
     {
         for( sal_Unicode cBuiltinId = 0; cBuiltinId < SAL_N_ELEMENTS( sppcBaseNames ); ++cBuiltinId )
         {
             OUString aBaseName = lclGetBaseName( cBuiltinId );
             sal_Int32 nBaseNameLen = aBaseName.getLength();
-            if( (rModelName.getLength() == nPrefixLen + nBaseNameLen) && rModelName.matchIgnoreAsciiCase( aBaseName, nPrefixLen ) )
+            if( (rModelName.getLength() == spcOoxPrefix.size + nBaseNameLen) && rModelName.matchIgnoreAsciiCase( aBaseName, spcOoxPrefix.size ) )
                 return cBuiltinId;
         }
     }
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index c29ee10..f4c7469 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2326,7 +2326,6 @@ void Dxf::fillToItemSet( SfxItemSet& rSet ) const
 
 namespace {
 
-const sal_Char* const spcStyleNamePrefix = "Excel Built-in ";
 const sal_Char* const sppcStyleNames[] =
 {
     "Normal",
@@ -2389,8 +2388,7 @@ const sal_Int32 snStyleNamesCount = static_cast< sal_Int32 >( SAL_N_ELEMENTS( sp
 OUString lclGetBuiltinStyleName( sal_Int32 nBuiltinId, const OUString& rName, sal_Int32 nLevel = 0 )
 {
     OSL_ENSURE( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount), "lclGetBuiltinStyleName - unknown built-in style" );
-    OUStringBuffer aStyleName;
-    aStyleName.appendAscii( spcStyleNamePrefix );
+    OUStringBuffer aStyleName("Excel Built-in ");
     if( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount) && (sppcStyleNames[ nBuiltinId ] != nullptr) )
         aStyleName.appendAscii( sppcStyleNames[ nBuiltinId ] );
     else if( !rName.isEmpty() )
diff --git a/scripting/source/protocolhandler/scripthandler.cxx b/scripting/source/protocolhandler/scripthandler.cxx
index cd82b19..8decdb26 100644
--- a/scripting/source/protocolhandler/scripthandler.cxx
+++ b/scripting/source/protocolhandler/scripthandler.cxx
@@ -67,9 +67,6 @@ using namespace ::com::sun::star::document;
 namespace scripting_protocolhandler
 {
 
-const sal_Char * const MYSERVICENAME = "com.sun.star.frame.ProtocolHandler";
-const sal_Char * const MYIMPLNAME = "com.sun.star.comp.ScriptProtocolHandler";
-
 void SAL_CALL ScriptProtocolHandler::initialize(
     const css::uno::Sequence < css::uno::Any >& aArguments )
     throw ( css::uno::Exception, std::exception )
@@ -468,14 +465,13 @@ throw( RuntimeException, std::exception )
 /* Helper for XServiceInfo */
 Sequence< OUString > ScriptProtocolHandler::impl_getStaticSupportedServiceNames()
 {
-    Sequence< OUString > seqServiceNames { OUString::createFromAscii(::scripting_protocolhandler::MYSERVICENAME) };
-    return seqServiceNames;
+    return {"com.sun.star.frame.ProtocolHandler"};
 }
 
 /* Helper for XServiceInfo */
 OUString ScriptProtocolHandler::impl_getStaticImplementationName()
 {
-    return OUString::createFromAscii( ::scripting_protocolhandler::MYIMPLNAME );
+    return OUString("com.sun.star.comp.ScriptProtocolHandler");
 }
 
 /* Helper for registry */


More information about the Libreoffice-commits mailing list