From 9e28127116e35797d373d7d147628a222c7f6ad6 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sat, 7 Dec 2019 17:18:08 +0100 Subject: tdf#59327: two arguments with the same name is an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8d10487d6d6729de749a373feb0a8a349f2986e9 Reviewed-on: https://gerrit.libreoffice.org/84686 Tested-by: Jenkins Reviewed-by: Mike Kaganski (cherry picked from commit 0ed214fd8f64eca4f3192b1646595500d772b243) Reviewed-on: https://gerrit.libreoffice.org/84736 Reviewed-by: Xisco FaulĂ­ --- 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(-) 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 -- cgit