Fix crash after precompiling a CBot class with errors (#881)

dev-buzzingcars
krzys-h 2016-12-27 13:23:41 +01:00
parent f0550383d1
commit e325efa447
3 changed files with 25 additions and 11 deletions

View File

@ -275,10 +275,15 @@ public:
CBotCStack* pStack);
/*!
* \brief Compile1
* \param p
* \param pStack
* \return
* \brief Pre-compile a new class
* \param p[in, out] Pointer to first token of the class, will be updated to point to first token after the class definition
* \param pStack Compile stack
*
* This function is used to find the beginning and end of class definition.
*
* If any errors in the code are detected, this function will set the error on compile stack and return nullptr.
*
* \return Precompiled class, or nullptr in case of error
*/
static CBotClass* Compile1(CBotToken* &p,
CBotCStack* pStack);

View File

@ -60,11 +60,16 @@ public:
bool bLocal = true);
/*!
* \brief Compile1 Pre-compile a new function.
* \param p
* \param pStack
* \param pClass
* \return
* \brief Pre-compile a new function
* \param p[in, out] Pointer to first token of the function, will be updated to point to first token after the function definition
* \param pStack Compile stack
* \param pClass If this is a class method, pointer to class this function is part of, otherwise nullptr
*
* This function is used to find the beginning and end of function definition.
*
* If any errors in the code are detected, this function will set the error on compile stack and return nullptr.
*
* \return Precompiled function, or nullptr in case of error
*/
static CBotFunction* Compile1(CBotToken* &p,
CBotCStack* pStack,

View File

@ -93,11 +93,15 @@ bool CBotProgram::Compile(const std::string& program, std::vector<std::string>&
if ( p->GetType() == ID_CLASS ||
( p->GetType() == ID_PUBLIC && p->GetNext()->GetType() == ID_CLASS ))
{
m_classes.push_back(CBotClass::Compile1(p, pStack.get()));
CBotClass* newclass = CBotClass::Compile1(p, pStack.get());
if (newclass != nullptr)
m_classes.push_back(newclass);
}
else
{
m_functions.push_back(CBotFunction::Compile1(p, pStack.get(), nullptr));
CBotFunction* newfunc = CBotFunction::Compile1(p, pStack.get(), nullptr);
if (newfunc != nullptr)
m_functions.push_back(newfunc);
}
}