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); CBotCStack* pStack);
/*! /*!
* \brief Compile1 * \brief Pre-compile a new class
* \param p * \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 * \param pStack Compile stack
* \return *
* 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, static CBotClass* Compile1(CBotToken* &p,
CBotCStack* pStack); CBotCStack* pStack);

View File

@ -60,11 +60,16 @@ public:
bool bLocal = true); bool bLocal = true);
/*! /*!
* \brief Compile1 Pre-compile a new function. * \brief Pre-compile a new function
* \param p * \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 * \param pStack Compile stack
* \param pClass * \param pClass If this is a class method, pointer to class this function is part of, otherwise nullptr
* \return *
* 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, static CBotFunction* Compile1(CBotToken* &p,
CBotCStack* pStack, CBotCStack* pStack,

View File

@ -93,11 +93,15 @@ bool CBotProgram::Compile(const std::string& program, std::vector<std::string>&
if ( p->GetType() == ID_CLASS || if ( p->GetType() == ID_CLASS ||
( p->GetType() == ID_PUBLIC && p->GetNext()->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 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);
} }
} }