This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch debian/master in repository colobot.
commit eeea31408b5c92a3677e9b65fe168dab1377344d Author: Piotr Dziwinski <piot...@gmail.com> Date: Mon Nov 2 22:08:52 2015 +0000 Fix operator+ semantics in CBotString --- src/CBot/CBotDll.h | 2 +- src/CBot/CBotString.cpp | 16 ++++------------ test/unit/CBot/CBotString_test.cpp | 9 ++++++--- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 9027dfb..c05e1a5 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -397,8 +397,8 @@ public: const CBotString& operator=(const CBotString& stringSrc); const CBotString& operator=(const char ch); const CBotString& operator=(const char* pString); - const CBotString& operator+(const CBotString& str); friend CBotString operator+(const CBotString& string, const char* lpsz); + CBotString operator+(const CBotString& str); const CBotString& operator+=(const char ch); const CBotString& operator+=(const CBotString& str); diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index a4240b9..5f7792c 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -344,19 +344,11 @@ CBotString operator+(const CBotString& string, const char * lpsz) return s; } -const CBotString& CBotString::operator+(const CBotString& stringSrc) +CBotString CBotString::operator+(const CBotString& stringSrc) { - char* p = new char[m_lg+stringSrc.m_lg+1]; - - if (m_ptr!=nullptr) strcpy(p, m_ptr); - char* pp = p + m_lg; - if (stringSrc.m_ptr!=nullptr) strcpy(pp, stringSrc.m_ptr); - - delete[] m_ptr; - m_ptr = p; - m_lg += stringSrc.m_lg; - - return *this; + CBotString s(*this); + s += stringSrc; + return s; } const CBotString& CBotString::operator=(const char ch) diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp index 22171c6..ebec202 100644 --- a/test/unit/CBot/CBotString_test.cpp +++ b/test/unit/CBot/CBotString_test.cpp @@ -271,10 +271,13 @@ TEST(CBotString_Test, operatorAdd) CBotString botStr4("Colobot"); //-- C string - const char cStr1[7] = "olobot"; + const char* cStr1 = "olobot"; - botStr1 + botStr2; - botStr1 + botStr3; + botStr1 = botStr1 + botStr2; + botStr1 = botStr1 + botStr3; + EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); + + botStr1 = "C" + botStr3; EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); botStr1.Empty(); -- 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