[colobot] 105/145: Fix conversion to string with + operator

Didier Raboud odyx at moszumanska.debian.org
Mon Jul 11 12:56:22 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 6db2832577578dc7eda5c805513de99b5cf3ef22
Author: melex750 <melex750 at users.noreply.github.com>
Date:   Sun May 29 06:45:08 2016 -0400

    Fix conversion to string with + operator
---
 src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
index 23e1153..4132103 100644
--- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
+++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
@@ -214,6 +214,13 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
 
             type2 = pStk->GetTypResult();                       // what kind of results?
 
+            if ( type1.Eq(99) || type2.Eq(99) )                 // operand is void
+            {
+                pStack->SetError(CBotErrBadType2, &inst->m_token);
+                delete inst;
+                return nullptr;
+            }
+
             // what kind of result?
             int TypeRes = std::max( type1.GetType(CBotTypResult::GetTypeMode::NULL_AS_POINTER), type2.GetType(CBotTypResult::GetTypeMode::NULL_AS_POINTER) );
             if (typeOp == ID_ADD && type1.Eq(CBotTypString))
@@ -267,7 +274,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
                         return pStack->Return(nullptr, pStk);
                     }
 
-                    if ( TypeRes != CBotTypString )
+                    if ( TypeRes != CBotTypString )                     // keep string conversion
                         TypeRes = std::max(type1.GetType(), type2.GetType());
                     inst = i;
                 }
@@ -370,7 +377,9 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
     // what kind of result?
     int TypeRes = std::max(type1.GetType(), type2.GetType());
 
-    if ( GetTokenType() == ID_ADD && type1.Eq(CBotTypString) )
+    // see "any type convertible chain" in compile method
+    if ( GetTokenType() == ID_ADD &&
+        (type1.Eq(CBotTypString) || type2.Eq(CBotTypString)) )
     {
         TypeRes = CBotTypString;
     }
@@ -397,7 +406,8 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
     CBotVar*    result = CBotVar::Create("", TypeRes);
 
     // creates a variable to perform the calculation in the appropriate type
-    TypeRes = std::max(type1.GetType(), type2.GetType());
+    if ( TypeRes != CBotTypString )                                     // keep string conversion
+        TypeRes = std::max(type1.GetType(), type2.GetType());
 
     if ( GetTokenType() == ID_ADD && type1.Eq(CBotTypString) )
     {

-- 
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