[EMAIL PROTECTED] (Lars Gullik Bjønnes) writes:


| lyxstring::size_type lyxstring::rfind(value_type c, size_type i) const
| {
|       size_type ii = min(rep->sz - 1, i);
|         for (size_type t = ii; t != 0; --t) {
|               if (rep->s[t] == c) return t;
|       }
|         return npos;
| }
| 
| 
| Hmm, well actually I see how it can fail... and we are lucky that it
| does not crash.
| 
| When running rfind on an empty string with i == npos, ii wil be set to
| -1. -1 != 0 so the loop runs... and then som unknown negative value is
| converted into an unsigned char and we have a large value that looks
| almost like npos.
| 
| I guess the fix is to have "...; t > 0; ..." in the test.

I belive this will have the same problem as the current code: the
first char in a string will never be tested.

 "...; t >= 0; ..." should be correct.

        Lgb

Reply via email to