[prev in list] [next in list] [prev in thread] [next in thread] 

List:       taglib-devel
Subject:    Re: cstring returning invalid encoding? mp3's
From:       Michael Pyne <mpyne () purinchu ! net>
Date:       2009-09-23 0:46:29
Message-ID: 200909222046.35867.mpyne () purinchu ! net
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


On Tuesday 22 September 2009 07:18:07 rengels wrote:
> On Tuesday 22 September 2009 01:55:49 am ext Caleb Cushing wrote:
> > figured it out 20-ish minutes ago... memory corruption. apparently the
> > memory was popping off the stack before the pointer was assigned (or
> > something like that).  using an intermediate variable.
> >
> >
> >             TagLib::String s( tfile.tag()->title() );
> >             const char *ttitle = s.toCString(true);
> >
> > has solved this issue.
> 
> Hi Caleb,
> it should not do that.
> As tfile does not run out of scope tag and tag->title should also remain
>  valid. Strange...

tfile was not the issue, it was a temporary String returned by tfile.tag()-
>title().

Look at the API docs: 
http://developer.kde.org/~wheeler/taglib/api/classTagLib_1_1String.html#ac86b42f97707048978f4ac9dd801959

"This string remains valid until the String instance is destroyed or another 
export method is called."

With tfile.tag()->title().toCString(true);, the temporary String returned by 
title() is destroyed essentially as soon as that semicolon is encountered, 
leaving the memory pointed to by ttitle in an undefined state.  Forcing the 
String to stay alive by storing it in a local variable also keeps the ttitle 
pointer valid.

Regards,
 - Michael Pyne

["signature.asc" (application/pgp-signature)]

_______________________________________________
taglib-devel mailing list
taglib-devel@kde.org
https://mail.kde.org/mailman/listinfo/taglib-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic