Results 1 to 3 of 3

Thread: CL_Exception::what() returns invalid pointer if UNICODE is #defined

  1. #1
    Serf
    Join Date
    Oct 2009
    Posts
    1

    Default CL_Exception::what() returns invalid pointer if UNICODE is #defined

    With ClanLib 2.0.4 I noticed that printing a ClanLib-thrown exception caught as a std::exception produced only nonsense bytes which varied every run. Running under valgrind confirmed my suspicions: an invalid pointer was coming up.

    I found the problem soon enough: CL_Exception::what() constructs a temporary CL_String8 using CL_StringHelp::text_to_local8 and then returns its c_str(). Unfortunately, that temporary is released when what() returns.

    When UNICODE is not #defined, this problem doesn't show up, since text_to_local8 simply returns the given string, which is stored safely inside the CL_Exception. With UNICODE #defined, however, text_to_local8 does create a new string which is then immediately freed by its destructor on returning from what(), and we have a classic "use after free" situation.

    I don't know enough about the ClanLib internals to know how this should be fixed (I'm just starting out with it), so I'm afraid I can't provide a patch. It's not a completely horrible issue as it's relatively easy to work around: catch CL_Exception separately from std::exception and use e.message there instead of e.what().

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

    Default

    Yeah, we need to...

    add: "private: CL_String8 buffer;" in CL_Exception class

    And "buffer = CL_StringHelp::text_to_local8(message);" in what()

    (I was informed)

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

    Default

    Fixed in SVN

Similar Threads

  1. UDP recv returns -1
    By nokturn in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 05-31-2007, 12:36 PM
  2. unicode support!
    By liver2006 in forum Novashell Game Creation System
    Replies: 3
    Last Post: 02-25-2007, 09:59 AM
  3. pointer
    By in forum Dink Smallwood HD
    Replies: 2
    Last Post: 07-26-2003, 05:42 PM
  4. Scripting in Unicode?
    By jjohn in forum Funeral Quest
    Replies: 3
    Last Post: 12-18-2002, 06:32 AM

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
  •