[PATCH] weird filename corruption

Scott Wheeler wheeler at kde.org
Tue Apr 22 15:48:47 CEST 2008


Alex Merry wrote:
>
> I've been having a bizarre problem where I'd get errors like this:
>
> TagLib: Could not open file 
> /home/music/A/Hi-Fi_Serious/11_W.D.y.C.A.I..¡p3
>
> Note that the 'm' of 'mp3' has been replaced, with an i in this case. The
>
> character it is replaced with is not consistent, and sometimes it 
> disappears
>
> altogether or the string cuts off at that point.
>

Usually an error like that comes from keeping a pointer to the output of 
c_str() for longer than the lifetime of the std::string it came from.  I 
can't be certain that it's not a TagLib bug, but I suspect the bug is in 
the calling code.  Can you paste it in?  Here's what you're looking for:

std::string foo()
{
    return "foo.mp3";
}

void bar()
{
    const char *s = foo().c_str();
    TagLib::File file(s); // <-- memory corruption, the std::string 
returned in the last function has passed out of scope taking the c_str() 
with it.
}


-Scott


More information about the taglib-devel mailing list