[colobot] 230/377: Fixed CBotClass::FreeLock crash on some compilers

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:20 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 84521ef08a700702019e51e0e0bbee4870d3fe6e
Author: krzys-h <krzys_h at interia.pl>
Date:   Sat Jan 23 21:33:58 2016 +0100

    Fixed CBotClass::FreeLock crash on some compilers
---
 src/CBot/CBotClass.cpp | 7 ++++++-
 src/CBot/CBotClass.h   | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index a3ee74d..dc99761 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -148,7 +148,12 @@ void CBotClass::FreeLock(CBotProgram* prog)
             pClass->m_lockCurrentCount = 0;
         }
 
-        pClass->m_lockProg.erase(std::remove(pClass->m_lockProg.begin(), pClass->m_lockProg.end(), prog));
+        // Note: erasing an end iterator is undefined behaviour
+        auto it = std::remove(pClass->m_lockProg.begin(), pClass->m_lockProg.end(), prog);
+        if (it != pClass->m_lockProg.end())
+        {
+            pClass->m_lockProg.erase(it);
+        }
     }
 }
 
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index a826911..03e61ef 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -387,7 +387,7 @@ private:
 
     //! How many times the program currently holding the lock called Lock()
     int m_lockCurrentCount = 0;
-    //! Programs waiting for lock
+    //! Programs waiting for lock. m_lockProg[0] is the program currently holding the lock, if any
     std::deque<CBotProgram*> m_lockProg{};
 };
 

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