From 0d74b4f36b8e9fbd6236c56976d82abf56545fea Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 16:56:17 -0400 Subject: [PATCH 1/5] Fix initializing an array using variables Resolves a conflict between CBotListArray and CBotExprVar --- src/CBot/CBotInstr/CBotListArray.cpp | 19 +++++++++---------- src/CBot/CBotInstr/CBotListArray.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 559bb9d9..89cbb79a 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -98,7 +98,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } } - inst->m_expr->AddNext3(i); + inst->m_expr->AddNext3b(i); if ( p->GetType() == ID_COMMA ) continue; if ( p->GetType() == ID_CLBLK ) break; @@ -114,10 +114,10 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu { goto error; } - CBotVar* pv = pStk->GetVar(); // result of the expression - if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) + CBotTypResult valType = pStk->GetTypResult(); + + if (!TypeCompatible(valType, type, ID_ASS) ) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; @@ -133,15 +133,14 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu goto error; } - CBotVar* pv = pStk->GetVar(); // result of the expression + CBotTypResult valType = pStk->GetTypResult(); - if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) + if (!TypeCompatible(valType, type, ID_ASS) ) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } - inst->m_expr->AddNext3(i); + inst->m_expr->AddNext3b(i); if (p->GetType() == ID_COMMA) continue; if (p->GetType() == ID_CLBLK) break; @@ -175,7 +174,7 @@ bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) int n = 0; - for (; p != nullptr ; n++, p = p->GetNext3()) + for (; p != nullptr ; n++, p = p->GetNext3b()) { if (pile1->GetState() > n) continue; @@ -207,7 +206,7 @@ void CBotListArray::RestoreState(CBotStack* &pj, bool bMain) int state = pile->GetState(); - while(state-- > 0) p = p->GetNext3() ; + while(state-- > 0) p = p->GetNext3b() ; p->RestoreState(pile, bMain); // size calculation //interrupted! } diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index c5f800b0..18d6b567 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -62,7 +62,7 @@ protected: virtual std::map GetDebugLinks() override; private: - //! An expression for an element others are linked with CBotInstr :: m_next3; + //! An expression for an element others are linked with CBotInstr :: m_next3b; CBotInstr* m_expr; }; From 66984a4bb3a0c3249322b85184f8d3c17953fb59 Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 17:00:41 -0400 Subject: [PATCH 2/5] Fix using compound-assignment with an array ...that was initialized in the definition --- src/CBot/CBotInstr/CBotDefArray.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/CBot/CBotInstr/CBotDefArray.cpp b/src/CBot/CBotInstr/CBotDefArray.cpp index 473fdc8d..c1995d92 100644 --- a/src/CBot/CBotInstr/CBotDefArray.cpp +++ b/src/CBot/CBotInstr/CBotDefArray.cpp @@ -121,6 +121,15 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul } } } + + if (pStk->IsOk()) while (true) // mark initialized + { + var = var->GetItem(0, true); + if (var == nullptr) break; + if (var->GetType() == CBotTypArrayPointer) continue; + if (var->GetType() <= CBotTypString) var->SetInit(CBotVar::InitType::DEF); + break; + } } if (pStk->IsOk()) return pStack->Return(inst, pStk); From 51665e8396800391fdc9a7eb20df824ab28ed033 Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 17:03:50 -0400 Subject: [PATCH 3/5] Fix "new" keyword syntax checking --- src/CBot/CBotInstr/CBotNew.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 7da8e417..a302b394 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -50,7 +50,11 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) if (!IsOfType(p, ID_NEW)) return nullptr; // verifies that the token is a class name - if (p->GetType() != TokenTypVar) return nullptr; + if (p->GetType() != TokenTypVar) + { + pStack->SetError(CBotErrBadNew, p); + return nullptr; + } CBotClass* pClass = CBotClass::Find(p); if (pClass == nullptr) From 64157090e66aeb5cec7ac1b72748ac1eeeb09dfa Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 17:18:11 -0400 Subject: [PATCH 4/5] Fix crash when calling method on a null object --- src/CBot/CBotInstr/CBotInstrMethode.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index e0d08a99..3bdf8492 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -103,6 +103,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre if (pVar->GetPointer() == nullptr) { pj->SetError(CBotErrNull, prevToken); + return pj->Return(pile1); } if (pile1->IfStep()) return false; From d0d0c4f197f82fa4aa134cdd6ab2c436c1748715 Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 17:29:32 -0400 Subject: [PATCH 5/5] Fix class not unlocked when program is stopped #626 --- src/CBot/CBotProgram.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index dde36bb4..d0284ea2 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -214,6 +214,7 @@ bool CBotProgram::Run(void* pUser, int timer) m_error = m_stack->GetError(m_errorStart, m_errorEnd); m_stack->Delete(); m_stack = nullptr; + CBotClass::FreeLock(this); return true; // execution is finished! } @@ -226,6 +227,7 @@ void CBotProgram::Stop() m_stack->Delete(); m_stack = nullptr; m_entryPoint = nullptr; + CBotClass::FreeLock(this); } ////////////////////////////////////////////////////////////////////////////////