This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
problem with find_last* in bastring
- To: egcs-bugs at cygnus dot com
- Subject: problem with find_last* in bastring
- From: scott snyder <snyder at d0sgif dot fnal dot gov>
- Date: Tue, 28 Oct 1997 22:08:06 -0600 (CST)
hi -
I ran into a problem with the bastring class in the 971023 snapshot
of egcs (i'm using a mips-sgi-irix5.3 system).
The following program:
- ts.cc ---------------------------------------------------------------------
#include <string>
#include <iostream.h>
main ()
{
string s = "a ";
cout << s.find_last_not_of (' ') << "\n";
cout << s.find_last_not_of (" ") << "\n";
cout << s.find_last_of ("a") << "\n";
s = "aa ";
cout << s.find_last_not_of (' ') << "\n";
cout << s.find_last_not_of (" ") << "\n";
cout << s.find_last_of ("a") << "\n";
}
-----------------------------------------------------------------------------
Gives this output:
% g++ -o ts ts.cc
% ./ts
4294967295
4294967295
4294967295
1
1
1
(I would expect 0 0 0 1 1 1 .)
Here's a patch.
Index: bastring.cc
===================================================================
RCS file: /d0sgi0/usr0/snyder/CVSROOT/egcs/libstdc++/std/bastring.cc,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 bastring.cc
*** 1.1.1.1 1997/10/17 19:11:26
--- bastring.cc 1997/10/29 03:38:01
***************
*** 318,324 ****
size_t xpos = length () - 1;
if (xpos > pos)
xpos = pos;
! for (; xpos; --xpos)
if (_find (s, data () [xpos], 0, n) != npos)
return xpos;
return npos;
--- 318,324 ----
size_t xpos = length () - 1;
if (xpos > pos)
xpos = pos;
! for (; xpos != npos; --xpos)
if (_find (s, data () [xpos], 0, n) != npos)
return xpos;
return npos;
***************
*** 353,359 ****
size_t xpos = length () - 1;
if (xpos > pos)
xpos = pos;
! for (; xpos; --xpos)
if (_find (s, data () [xpos], 0, n) == npos)
return xpos;
return npos;
--- 353,359 ----
size_t xpos = length () - 1;
if (xpos > pos)
xpos = pos;
! for (; xpos != npos; --xpos)
if (_find (s, data () [xpos], 0, n) == npos)
return xpos;
return npos;
***************
*** 366,372 ****
size_t xpos = length () - 1;
if (xpos > pos)
xpos = pos;
! for (; xpos; --xpos)
if (traits::ne (data () [xpos], c))
return xpos;
return npos;
--- 366,372 ----
size_t xpos = length () - 1;
if (xpos > pos)
xpos = pos;
! for (; xpos != npos; --xpos)
if (traits::ne (data () [xpos], c))
return xpos;
return npos;
thanks,
sss