This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug in libstdc++ string class of egcs 1.1b


Greetings,

  I think I found a strange bug in the string class of the libstdc++
of the egcs 1.1 release. Following is a fast hack showing the symptoms:

****

#include <string>
#include "tokenizer.hh"

int main() {

  // The String Tokenizer class...not of importance...it just
  // takes two arguments...a string and a 'seperator' string...then
  // the class splits the 'substrings' which are seperated by the
  // 'seperators'.
  tokenizer test_tok("Hit p.:[929/999(1261)", " ");

  // The amount of found tokens is printed out.
  cout << "Amount of Tokens in Tokenizer: " << test_tok.size() << endl;

  cout << "The Tokens are:" << endl;

  // The single tokens are printed out
  for (int i = 0; i < test_tok.size(); ++i)
    cout << "Token nr " << i << ": " << test_tok[i] << endl;

  cout << endl << endl;

  // The string:
  string faulty_string = "";

  // Iteration with cat'ting the tokens to the string with operator+=
  for (int i = 0; i < test_tok.size();++i) {
    faulty_string += test_tok[i];
    cout << "Token after iteration " << i << ": " << test_tok[i] << endl;
    cout << "String after iteration " << i << ": " << faulty_string << endl;
  }
  cout << faulty_string << endl;
}

***

This program gives the following output:

***
Amount of Tokens in Tokenizer: 2
The Tokens are:
Token nr 0: Hit
Token nr 1: p.:[929/999(1261)


Token after iteration 0: Hit
String after iteration 0: Hit
Token after iteration 1: p.:[929/999(1261)
String after iteration 1: HitHitHitHitHitHitHi
HitHitHitHitHitHitHi
***

I compiled with the following options:

g++ -O2 -fno-rtti -fno-exceptions -mpentium -march=pentium 
    tokenizer.o -o tok_test tokentest.cc

I hope I could help with this bugreport...any mails cc to me please,
as I'm not subscribed to the list...

- Chris

 -- 
/----------------------------------------------------------------------------\
| Christian Loth, chris@rom.mud.de    |           REALM OF MAGIC             |
| http://rom.mud.de/~chris            | telnet rom.mud.de 4000               |
|                                     | http://rom.mud.de/                   |
\----------------------------------------------------------------------------/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]