I have no clear idea either (since you asked me). The code was written
by Abdel, I just copied it over from LayoutBox. But I try:

Am Freitag, den 10.03.2017, 11:34 +0100 schrieb Jean-Marc Lasgouttes:
> 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?

AFAICS it can actually be -1, if the filter string is not found. So we
probably should not assert here, but leave the loop.

So

- LASSERT(p != -1, /**/);
+ if (p < 0)
+     break;

> 
> I have problems actually to run the code and see where the
> underlines 
> appear. 

Document > Settings. Unfold the class combo and type, for instance,
"yw".

> The code itself is not very clear.

The condition above, AFAICS, looks for consecutive matching strings
which are then concatenated, i.e.

<u>found</u>found... -> <u>foundfound</u>...

If the condition does not match, the matching string only applies to
the actual hit, so it is wrapped in <u>...</u>

> 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?

I suppose it can be removed (also in LayoutBox.cpp).

Jürgen

> 
> JMarc

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to