Question

When built with the latest XCode 5.1, iOS SDK 7.1 and LLVM 5.1, using libstdc++ for the C++ standard library, get crash in the std::string append method only on iOS 5.1 device.

Here's code example:

class TestClass
{
public:
    TestClass()
    {
        m_string = "string1";
    }

    void AppendString()
    {
        m_string += std::string("string2");
        std::string newString2 = m_string + "string3";
    }

private:
    string m_string;
};

App crashes in AppendString() method on this line:

        std::string newString2 = m_string + "string3";

If I remove this line m_string += std::string("string2"); before creating newString2, code works fine.

Here's the stacktrace of crash:

#0  0x34c99fe8 in memcpy$VARIANT$CortexA8 ()
#1  0x3706f95a in std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned long) ()
#2  0x3706fbfa in std::string::reserve(unsigned long) ()
#3  0x3706fdb0 in std::string::append(char const*, unsigned long) ()
#4  0x000c0e5a in std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*) [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/include/c++/4.2.1/bits/basic_string.h:2121
#5  0x000c0e3c in TestClass::AppendString() at /Users/sergei/Documents/2_3/House of Fun/cpp/CasinoSceneManager.cpp:122

Have anybody experinced same crash? It happens only on devices with iOS 5.1 and 5.1.1 and only if app was compiled with release flag, not debug.

Thank you for the help.


One more note. If I change Optimization level to None [-O0] in Code Generation section in project settings, everything works fine. Maybe the problem has some connection to code optimization.

Was it helpful?

Solution

Apple released a new GM seed for Xcode 5.1.1. In the release notes they say they fixed a couple crashes:

Fixed a compiled code crash on when targeting iOS 5.1.1. (16485980)!

Fixed a compiled code crash when using ARC and C++. (16368824)

http://adcdownload.apple.com//Developer_Tools/xcode_5.1.1_gm_seed/release_notes_xcode_5.1.1_gm_seed.pdf

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top