[PATCH] Check url in KDirModelPrivate::nodeForUrl()

Aurélien Gâteau aurelien.gateau at free.fr
Fri Jul 20 08:56:28 BST 2007


David Faure wrote:

> On Wednesday 18 July 2007, Aurélien Gâteau wrote:
>> Hello,
>> 
>> If you call KDirModel::itemForUrl(url) with an invalid url, an assert
>> fails in KDirModelPrivate::nodeForUrl(). Attached patch fixes this by
>> returning an invalid index instead. Is it the correct behavior? Is it ok
>> to commit?
> 
> OK, you're not the first one who expects more builtin-checks rather than
> contract-based programming, so I don't object to the patch.
> 
> I would just like to note that this assert has helped detect some
> application bugs in the past... The question one should be asking himself
> is, why am I calling this method with an invalid URL (or one that is
> unrelated to the dirmodel)...

I understand, but even with the patch you still get a warning on the
console, so there is still a hint that something is going wrong (Assuming
your console is not too flooded with other messages).

Besides, I don't think it goes against the goal of the method: in my case I
was calling indexForUrl(), if I pass an url which is not in the model, I
expect it to return an invalid index.

I just committed it in r690169.

Aurélien





More information about the kde-core-devel mailing list