[colobot] 27/100: Fix crash after precompiling a CBot class with errors (#881)
Didier Raboud
odyx at moszumanska.debian.org
Thu Jun 1 18:10:15 UTC 2017
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit e325efa447ecff282ad59515f58b119325c0be07
Author: krzys-h <krzys_h at interia.pl>
Date: Tue Dec 27 13:23:41 2016 +0100
Fix crash after precompiling a CBot class with errors (#881)
---
src/CBot/CBotClass.h | 13 +++++++++----
src/CBot/CBotInstr/CBotFunction.h | 15 ++++++++++-----
src/CBot/CBotProgram.cpp | 8 ++++++--
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index 10bb83c..68b61cc 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -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);
diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h
index 66637b5..bab5e2b 100644
--- a/src/CBot/CBotInstr/CBotFunction.h
+++ b/src/CBot/CBotInstr/CBotFunction.h
@@ -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,
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index fdb36eb..dce6219 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -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);
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list