| | | | Browse by category |
Article ID: 835
Last updated: 05 Feb, 2008
Problem
The following simple program will not produce the correct result:
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:
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) {Add the next line:
if (pref()->references() == 1) {
pref()->nchars_ = 0;
*data_ = '\0';
}
This article was:
Helpful |
Not helpful
Report an issue
Article ID: 835
Last updated: 05 Feb, 2008
Revision: 1
Views: 5868
Posted: 25 Jun, 1997 by
Dean J.
Updated: 05 Feb, 2008 by
Dean J.
Others in this category
Powered by KBPublisher (Knowledge base software)