This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 6b8e240d26ea07b79e28899577ee2942a141b59d
Author: Jeremy Mickelson <jeremy.mickel...@gmail.com>
Date:   Sun Aug 7 08:27:01 2016 -0400

    Fix implicit downcast with variable initialization
---
 src/CBot/CBotInstr/CBotDefClass.cpp | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp 
b/src/CBot/CBotInstr/CBotDefClass.cpp
index 4c9ea4d..bfd0ded 100644
--- a/src/CBot/CBotInstr/CBotDefClass.cpp
+++ b/src/CBot/CBotInstr/CBotDefClass.cpp
@@ -174,7 +174,8 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* 
pStack, CBotClass* p
             CBotClass* result = pStk->GetClass();
             if ( 
!pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypNullPointer)
 &&
                ( 
!pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypPointer) 
||
-                 ( result != nullptr && !result->IsChildOf(pClass) )))     // 
type compatible ?
+                 ( result != nullptr && !(pClass->IsChildOf(result) ||
+                                          result->IsChildOf(pClass)))))     // 
type compatible ?
             {
                 pStk->SetError(CBotErrBadType1, p->GetStart());
                 goto error;
@@ -268,9 +269,10 @@ bool CBotDefClass::Execute(CBotStack* &pj)
             // evaluates the expression for the assignment
             if (!m_expr->Execute(pile)) return false;
 
+            CBotVar* pv = pile->GetVar();
+
             if ( bIntrincic )
             {
-                CBotVar*    pv = pile->GetVar();
                 if ( pv == nullptr || pv->GetPointer() == nullptr )
                 {
                     pile->SetError(CBotErrNull, &m_token);
@@ -280,8 +282,17 @@ bool CBotDefClass::Execute(CBotStack* &pj)
             }
             else
             {
+                if ( !(pv == nullptr || pv->GetPointer() == nullptr) )
+                {
+                    if ( !pv->GetClass()->IsChildOf(pClass))
+                    {
+                        pile->SetError(CBotErrBadType1, &m_token);
+                        return pj->Return(pile);
+                    }
+                }
+
                 CBotVarClass* pInstance;
-                pInstance = 
(static_cast<CBotVarPointer*>(pile->GetVar()))->GetPointer();    // value for 
the assignment
+                pInstance = pv->GetPointer();    // value for the assignment
                 CBotTypResult type = pThis->GetTypResult();
                 pThis->SetPointer(pInstance);
                 pThis->SetType(type);        // keep pointer type

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/colobot.git

_______________________________________________
Pkg-games-commits mailing list
Pkg-games-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to