Results 1 to 2 of 2

Thread: Crash in CL_StringReference

  1. #1

    Default Crash in CL_StringReference

    I encountered a crash (failed debug assertion in CRT) after using a std::string argument in cl_format. The crash is located in the clear() function of CL_String Reference, where memory is freed which has never been allocated.
    After looking through create_temp() and clear(), I think the problem comes from the initialization value of the member 'temporary' in the CL_StringReference constructor of a std::string. It is initialized with true, but no temporary is created and no memory is allocated. There should be no reason to initialize it to true in any case, because the allocation of memory happens only in create_temp() which sets the variable to true afterwards anyway.
    A test with the member initialized to false shows no crashes anymore and I can see no reason why it would have any sideeffects, since the only change is that the memory won't be freed in clear().

    To reproduce the crash, the following line of code can be used:
    Code:
    std::string test( cl_format( "%1", std::string( "test" ) ) );
    It's not only with temporary objects, so the following shows the same behavior:
    Code:
    std::string test1( "test" );
    std::string test2( cl_format( "%1", test1 ) );
    I can provide a patch if necessary, but the only change is initializing the member 'temporary' with false in \Core\Text\string_reference.cpp on line 63. A patch may be overkill in this case.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Well spotted

    Patch applied (to SVN), many thanks

Similar Threads

  1. Font crash in GUI
    By Harry in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 07-23-2009, 01:47 AM
  2. Crash
    By valdirSalgueiro in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 03-14-2009, 01:47 AM
  3. Game.exe crash
    By Viscos in forum Novashell Game Creation System
    Replies: 1
    Last Post: 11-16-2007, 11:12 PM
  4. nosound crash at startup
    By sphair in forum Novashell Game Creation System
    Replies: 1
    Last Post: 02-07-2007, 07:04 AM
  5. Crash when destroying a DisplayWindow
    By Wuntvor in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 09-19-2006, 07:31 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •