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]

simple bastring bug [egcs-1.03a (2.90.29)]



It appears that appending a character string to a "string" does not
give a null-terminated string. The appended test program shows this.
I do not think this should be the behaviour. To copy the terminating
null, one should use traits::length(s)+1 when appending/replacing. 

Andrew Mauer-Oats
mauer@uiuc.edu

========================================================================
#include <iostream.h>
#include <string>

int main (void)
{
     string x("ThisEndlessTrialOppressesMe");
     const char *frob = "/file-------";

     cout << x << endl;
     x = "/opt";
     cout << x << endl;
     x += frob;
     cout << x << endl;

     printf("As a string, x = %s\n",x.data());
	  
     return 0;
}

========================================================================
ThisEndlessTrialOppressesMe
/opt
/opt/file-------
As a string, x = /opt/file-------OppressesMe
========================================================================


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