Error when calling Amarok::decapitateString()

Pavel Shved pavel.shved at gmail.com
Thu Jan 8 17:30:54 UTC 2009


Nicholas Sinlock wrote:

> According to the crash handler, and some testing on my part, the crash 
> appears to be originating in the decapitateString function
> and, if I'm reading it correctly, having something to do with the chName 
> string.   But no matter what I do, even if I use a simple
> quoted string, like "60 Second Science", I recieve the same error.   
> Here's the decapitateString function code.
> 
>     QString decapitateString( const QString &input, const QString &ref )

Apart from how decapitateString() is called it obviously aims to strip 
common prefix of two strings from input string, then strip non-word 
characters from the beginning and return the result.  In order to 
obfuscate code (i can't imagine any other reason) it is written in 
obscure, non-effective and longer way.

ref.at(t.length() ) is sometimes out of range in this condition here

>         if( t.endsWith( ' ' ) || !ref.at( t.length() 

as t is the common prefix of strings and it may sometimes coincide with 
one (or both--which is your case obviously) of them.

Fix it like that:

 > if( !t.length()>=ref.length()) if (t.endsWith( ' ' ) || !ref.at( 
t.length()

or completely rewrite the function (better solution imho).

Probably, the coder was confused that QString::left() function accepts 
range violation and extrapolated it to at() function, that doesn't.

And probably problem isn't in this particular function because, if it is 
called with particular parameters, it works ok.  The problem may be in 
caller, so the backtrace (as already asked for by the other poster) may 
be useful for developers.



More information about the Amarok mailing list