[colobot] 22/74: Fix implicit downcast with variable initialization

Didier Raboud odyx at moszumanska.debian.org
Mon Nov 7 07:50:00 UTC 2016


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.Mickelson at 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



More information about the Pkg-games-commits mailing list