We have a coverity issue about the folowing code:

QString CCItemDelegate::underlineFilter(QString const & s) const
{
        QString const & f = cc_->filter();
        if (f.isEmpty())
                return s;

        // step through data item and put "(x)" for every matching character
        QString r;
        int lastp = -1;
        cc_->filter();
        for (int i = 0; i < f.length(); ++i) {
                int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
                LASSERT(p != -1, /**/);
                if (lastp == p - 1 && lastp != -1) {
                        // remove ")" and append "x)"
                        r = r.left(r.length() - 4) + s[p] + "</u>";

The issue is at the end where it asks "but how do you know that p>=0"?
A way to fix the coverity issue would be to assert on p>=0, but I have to ask: how do we know that p!=-1?

I have problems actually to run the code and see where the underlines appear. The code itself is not very clear.

An easy question to en the message: the lone "cc_->filter();" statement before the loop does nothing AFAIU. Was it supposed to be something else?

JMarc

Reply via email to