cstring returning invalid encoding? mp3's
Caleb Cushing
xenoterracide at gmail.com
Tue Sep 22 22:50:43 CEST 2009
> it should not do that.
> As tfile does not run out of scope tag and tag->title should also remain valid.
> Strange...
I'm not sure, but the person who helped me had run my program through
valgrind and said that's what it was. So apparently it's not just a
'my system' thing.
IRC convo logs... maybe this will help..
[Monday 21 September 2009] [18:15:28] <xenoterracide>
http://privatepaste.com/fd0oC6poSx I can't figure out why it's not
spitting out a cstring right from mp3's
[Monday 21 September 2009] [18:22:27] <diddly_> xenoterracide: without
knowing anything about taglib, looks like you are referencing
un-initialized memory. tried valgrind?
[Monday 21 September 2009] [18:24:20] <xenoterracide> diddly_:
nope... I suppose I could
[Monday 21 September 2009] [18:24:58] <diddly_> i just did
[Monday 21 September 2009] [18:25:26] <diddly_> does the title()
method perhaps create and return a temp variable? because if it does,
you have a ptr to a variable that fell off the stack after that call
in your code
[Monday 21 September 2009] [18:25:48] <xenoterracide> diddly_: I'm not sure...
[Monday 21 September 2009] [18:25:58] <diddly_> sec lemme check api,
i've never used taglib
[Monday 21 September 2009] [18:26:22] <xenoterracide> diddly_: I'm
addmittedly still a very amateur programmer...
[Monday 21 September 2009] [18:26:41] <diddly_> xenoterracide: only
one way to get better ;)
[Monday 21 September 2009] [18:27:59] <xenoterracide> diddly_:
right. practice practice practice. but like all professions... you
have to start somewhere and you can't do everything by yourself right
off the bat
[Monday 21 September 2009] [18:28:12] <diddly_> xenoterracide: no, i
meant ask questions in IRC ;)
[Monday 21 September 2009] [18:28:34] <xenoterracide> diddly_: lol
[Monday 21 September 2009] [18:29:30] <diddly_> xenoterracide: right
so your problem was that the title() method returns a TagLib::String
object. It since it was never stored, the object goes out of scope
immediately after that line of
[Monday 21 September 2009] [18:29:39] <diddly_> sec i'll paste a possible fix
[Monday 21 September 2009] [18:30:08] <xenoterracide> what I don't
get is why it only happens to the mp3's... and not the flac's
[Monday 21 September 2009] [18:30:21] <diddly_> http://dpaste.org/0dLo/
[Monday 21 September 2009] [18:31:05] <diddly_> just dumb luck, if the
flac object is smaller, the memory on the stack may not be re-used as
quickly and it still has data that hasnt been over-written yet
[Monday 21 September 2009] [18:31:29] <xenoterracide> ah
[Monday 21 September 2009] [18:31:32] <diddly_> its one of the more
subtle c++ bugs
[Monday 21 September 2009] [18:31:49] <xenoterracide> right
[Monday 21 September 2009] [18:32:23] <xenoterracide> remember the stack.
[Monday 21 September 2009] [18:32:24] <xenoterracide> fun
[Monday 21 September 2009] [18:33:51] <diddly_> typically if you see
behaviour like that (randomly changing output/results, given a fixed
input) it starts to yell memory corruption, and valgrind is your
quickest way to find it
--
Caleb Cushing
http://xenoterracide.blogspot.com
More information about the taglib-devel
mailing list