[Libreoffice-commits] core.git: basic/qa basic/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sat Dec 7 19:01:59 UTC 2019


 basic/qa/cppunit/test_complier_checks.cxx |    9 +++++++++
 basic/source/comp/dim.cxx                 |    9 ++++++++-
 basic/source/comp/symtbl.cxx              |    4 ++--
 basic/source/inc/symtbl.hxx               |    2 +-
 4 files changed, 20 insertions(+), 4 deletions(-)

New commits:
commit 0ed214fd8f64eca4f3192b1646595500d772b243
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Dec 7 17:18:08 2019 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Dec 7 20:01:16 2019 +0100

    tdf#59327: two arguments with the same name is an error
    
    Change-Id: I8d10487d6d6729de749a373feb0a8a349f2986e9
    Reviewed-on: https://gerrit.libreoffice.org/84686
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/basic/qa/cppunit/test_complier_checks.cxx b/basic/qa/cppunit/test_complier_checks.cxx
index aad058040c31..24b380ed2a9a 100644
--- a/basic/qa/cppunit/test_complier_checks.cxx
+++ b/basic/qa/cppunit/test_complier_checks.cxx
@@ -24,4 +24,13 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testRedefineArgument)
     CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic());
 }
 
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testDoubleArgument)
+{
+    MacroSnippet aMacro("Sub doUnitTest(argName, argName)\n"
+                        "End Sub\n");
+    aMacro.Compile();
+    CPPUNIT_ASSERT(aMacro.HasError());
+    CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx
index d6b2bff6ccc6..6e6c3e024d67 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -938,7 +938,14 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl )
                 {
                     pPar->SetParamArray();
                 }
-                pDef->GetParams().Add( pPar );
+                if (SbiSymDef* pOldDef = pDef->GetParams().Find(pPar->GetName(), false))
+                {
+                    Error(ERRCODE_BASIC_VAR_DEFINED, pPar->GetName());
+                    delete pPar;
+                    pPar = pOldDef;
+                }
+                else
+                    pDef->GetParams().Add( pPar );
                 SbiToken eTok = Next();
                 if( eTok != COMMA && eTok != RPAREN )
                 {
diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx
index 5de6be744e6a..b05575adfdfb 100644
--- a/basic/source/comp/symtbl.cxx
+++ b/basic/source/comp/symtbl.cxx
@@ -165,7 +165,7 @@ void SbiSymPool::Add( SbiSymDef* pDef )
 }
 
 
-SbiSymDef* SbiSymPool::Find( const OUString& rName )
+SbiSymDef* SbiSymPool::Find( const OUString& rName, bool bSearchInParents )
 {
     sal_uInt16 nCount = m_Data.size();
     for( sal_uInt16 i = 0; i < nCount; i++ )
@@ -177,7 +177,7 @@ SbiSymDef* SbiSymPool::Find( const OUString& rName )
             return &r;
         }
     }
-    if( pParent )
+    if( bSearchInParents && pParent )
     {
         return pParent->Find( rName );
     }
diff --git a/basic/source/inc/symtbl.hxx b/basic/source/inc/symtbl.hxx
index 629bd6728297..2dfc9c758bda 100644
--- a/basic/source/inc/symtbl.hxx
+++ b/basic/source/inc/symtbl.hxx
@@ -71,7 +71,7 @@ public:
     SbiSymDef* AddSym( const OUString& );
     SbiProcDef* AddProc( const OUString& );
     void Add( SbiSymDef* );
-    SbiSymDef* Find( const OUString& ); // variable name
+    SbiSymDef* Find( const OUString&, bool bSearchInParents = true ); // variable name
     SbiSymDef* Get( sal_uInt16 );     // find variable per position
     SbiSymDef* First(), *Next();            // iterators
 


More information about the Libreoffice-commits mailing list