Assigning the Empty String to an RWCString

Article ID: 835
Last updated: 05 Feb, 2008
Article ID: 835
Last updated: 05 Feb, 2008
Revision: 1
Views: 5224
Posted: 25 Jun, 1997
by Dean J.
Updated: 05 Feb, 2008
by Dean J.
Problem


The following simple program will not produce the correct result:
RWCString   str(Hallo);
str=;
cout << str << endl;


result: Hallo



Cause


Tools.h++ 6.1 added a performance enhancement for the case where you are assigning an RWCString and empty char* (). In this case, we simply set the length of the RWCString to zero. If you then call the data() member function, you can still see the original string because we do not set the first character of the buffer to a null.


Action


In the file toolsrc/cstring.cpp, the function RWCString::operator=() contains the following:
 if (!*cs) {
if (pref()->references() == 1) {
pref()->nchars_ = 0;
Add the next line:
     *data_ = '\0';
}
This article was:   Helpful | Not helpful
Report an issue
Article ID: 835
Last updated: 05 Feb, 2008
Revision: 1
Views: 5224
Posted: 25 Jun, 1997 by Dean J.
Updated: 05 Feb, 2008 by Dean J.

Others in this category