• 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
C++ std::string.resize calls append instead
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ std::string.resize calls append instead


  • Subject: C++ std::string.resize calls append instead
  • From: Jean-Denis Muys <email@hidden>
  • Date: Sun, 20 Sep 2009 00:41:41 +0200

Hello,

I'm facing a strange bug with some C++ sample code that only occurs when running from XCode, so I hope this is the right place to look for some help.

I just installed the Boost C++ library because I want to use its serialization facility.

Boost version 1.40 built and installed just fine following their instructions at http://www.boost.org/doc/libs/1_40_0/more/getting_started/unix-variants.html

The serialization demo program builds and runs just fine from the terminal. I built it that way:

c++ demo.cpp -o demo /usr/local/lib/libboost_serialization.dylib

Now my real project is under XCode 3.2 (on Snow Leopard) so I wanted to build and run the same demo program from XCode.

I set up a new project for a C++ tool in XCode, modified the header search path to add /usr/local/include/, added libboost_serialization.dylib, and it built without error.

However, it now breaks at runtime with the following error message from GDB:

malloc: *** error for object 0x1000581c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug


(BTW, I did set that breakpoint, but I don't know what to do next).

The stack crawl is the following:

#0 0x7fff81291b91 in malloc_error_break
#1 0x7fff811bb083 in free
#2 0x7fff836031e8 in std::string::reserve
#3 0x7fff836032fe in std::string::append
#4 0x100156cac in boost ::archive::text_iarchive_impl<boost::archive::text_iarchive>::load at text_iarchive_impl.ipp:55
#5 0x100024a0e in boost ::archive::load_access::load_primitive<boost::archive::text_iarchive, std::string> at iserializer.hpp:109
#6 0x100024a33 in boost ::archive ::detail::load_non_pointer_type<boost::archive::text_iarchive, std::string>::load_primitive::invoke at iserializer.hpp:332
#7 0x100024a58 in boost ::archive ::detail::load_non_pointer_type<boost::archive::text_iarchive, std::string>::invoke at iserializer.hpp:417
#8 0x100024a7d in boost::archive::load<boost::archive::text_iarchive, std::string> at iserializer.hpp:542
#9 0x100024aae in boost ::archive ::detail ::common_iarchive <boost::archive::text_iarchive>::load_override<std::string> at common_iarchive.hpp:61
#10 0x100024adb in boost ::archive ::basic_text_iarchive <boost::archive::text_iarchive>::load_override<std::string> at basic_text_iarchive.hpp:62
#11 0x100024b09 in boost ::archive ::text_iarchive_impl <boost::archive::text_iarchive>::load_override<std::string> at text_iarchive.hpp:66
#12 0x100024b3c in boost ::archive ::detail ::interface_iarchive <boost::archive::text_iarchive>::operator>><std::string> at interface_iarchive.hpp:61
#13 0x100024b73 in boost ::archive ::detail ::interface_iarchive <boost::archive::text_iarchive>::operator&<std::string> at interface_iarchive.hpp:68
#14 0x10002665e in bus_stop_corner::serialize<boost::archive::text_iarchive> at demo.cpp: 123


The interesting part is frame #4, the last frame for which I have the source code:

template<class Archive>
BOOST_ARCHIVE_DECL(void)
text_iarchive_impl<Archive>::load(std::string &s)
{
    std::size_t size;
    * this->This() >> size;
    // skip separating space
    is.get();
    // borland de-allocator fixup
    #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
    if(NULL != s.data())
    #endif
        s.resize(size);	// <============== crash on this line
    if(0 < size)
        is.read(&(*s.begin()), size);
}

The crash happens on the call to std::string.resize. But now what I don't get is why is the next stack frame in std::string::append and not std::string::resize?
(note that at crash time, the string s is the empty string and size == 11).


As far as I can see the problem is that the linker linked to std::string::append instead of std::string::resize.

The only explanation I have is that maybe Boost was built in a way that is incompatible with XCode.

So what does XCode do that's different from what the terminal c++ command does?

Has anyone been able to integrate Boost into an XCode project, ie those parts of Boost that are more than only headers?

Any help appreciated as I a relative newbie here.

Jean-Denis

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: C++ std::string.resize calls append instead
      • From: Howard Hinnant <email@hidden>
  • Prev by Date: Re: Problem using .zerofill / -segaddr to create very large segments
  • Next by Date: Re: Problem using .zerofill / -segaddr to create very large segments
  • Previous by thread: Re: Problem using .zerofill / -segaddr to create very large segments
  • Next by thread: Re: C++ std::string.resize calls append instead
  • Index(es):
    • Date
    • Thread