• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
std::string crash with optimisations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

std::string crash with optimisations


  • Subject: std::string crash with optimisations
  • From: Dario Accornero <email@hidden>
  • Date: Fri, 14 Nov 2003 16:52:01 +0100

Hello,

My Carbon application links against a few system frameworks plus three in-house static libraries. Building it on Jaguar with gcc 3.1 under PB 2.1 results in working debug and release versions. Building it on Panther with gcc 3.3 under Xcode results in working debug/non-working release versions -- the latters crash thusly:

Exception:  EXC_BAD_ACCESS (0x0001)
Codes:      KERN_INVALID_ADDRESS (0x0001) at 0x00cdd000

Thread 0 Crashed:
#0 0xffff8a50 in __memcpy (__memcpy + 688)
#1 0x0002e65c in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_M_clone(std::allocator<char> const&, unsigned long) (LWScenePlugIn.cpp:261)
#2 0x0002c5f0 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long) (LWScenePlugIn.cpp:261)
#3 0x0002ca2c in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(unsigned long, char) (LWScenePlugIn.cpp:261)
#4 0x00009b54 in Wml::MemFile::ReadEvenString(int*) (basic_string.h:483)


The guilty code is the following:

string MemFile::ReadEvenString (int* piBytes)
{
    string aStr;
    if ( m_bFileLoaded && DataAvailable() )
    {
        *piBytes = 0;
        bool bLoop = true;
        while ( bLoop )
        {
            char cCurrentChar = *m_pcCurrent++;
            ++(*piBytes);
            if ( cCurrentChar && DataAvailable() )
                aStr += cCurrentChar;
            else
            {
                if ( (*piBytes) & 1 )
                {
                    ++m_pcCurrent;
                    ++(*piBytes);
                }
                bLoop = false;
            }
        }
        m_lMarker += *piBytes;
    }
    return aStr;
}

The crash occurs on line

                aStr += cCurrentChar;

This looks legal to me, and it works fine when compiling with -O0. It works fine on Jaguar with gcc 3.1 even when compiling with -Os.

The offending source file, in release builds, has the following options:

-arch ppc -pipe -Wno-trigraphs -fno-rtti -fpascal-strings -g -O1 -Wno-four-char-constants -Wall -fmessage-length=0 -mtune=G4

Am I missing something or is there a known issue with std::string in non-O0 builds?

Thanks,
Dario
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: std::string crash with optimisations
      • From: Dario Accornero <email@hidden>
  • Prev by Date: Native targets with some applescripts -- how?
  • Next by Date: Re: Native targets with some applescripts -- how?
  • Previous by thread: Re: Native targets with some applescripts -- how?
  • Next by thread: Re: std::string crash with optimisations
  • Index(es):
    • Date
    • Thread