Microsoft KB Archive/172398: Difference between revisions
m (Text replacement - "<" to "<") |
m (Text replacement - """ to """) |
||
(One intermediate revision by the same user not shown) | |||
Line 59: | Line 59: | ||
<pre class="fixed_text">Debug Error! | <pre class="fixed_text">Debug Error! | ||
Program <your program name | Program <your program name> | ||
DAMAGE: after Normal block (#NNN) at 0xNNNNNNNN | DAMAGE: after Normal block (#NNN) at 0xNNNNNNNN | ||
</pre> | </pre> | ||
Line 94: | Line 94: | ||
<pre class="codesample"> //Compile options needed: /GX | <pre class="codesample"> //Compile options needed: /GX | ||
#include <crtdbg.h | #include <crtdbg.h> | ||
#include <string | #include <string> | ||
int main() | int main() | ||
{ | { | ||
std::string str, str2; | std::string str, str2; | ||
str = | str = "abcdefghijklmnopqrstuvwxyzabcdefghij" ; | ||
str2 = str; | str2 = str; | ||
Line 106: | Line 106: | ||
//str.erase() ; | //str.erase() ; | ||
str = | str = "zyxw" ; | ||
_CrtCheckMemory() ; | _CrtCheckMemory() ; | ||
Latest revision as of 11:06, 21 July 2020
Article ID: 172398
Article Last Modified on 11/18/2003
APPLIES TO
- The Standard C++ Library, when used with:
- Microsoft Visual C++ 5.0 Enterprise Edition
- Microsoft Visual C++ 5.0 Professional Edition
This article was previously published under Q172398
SYMPTOMS
When you assign a shorter string to an existing string that originally contained a longer string, the assignment corrupts the heap.
When running a debug build, you may see an assertion similar to the following:
CAUSE
This problem is due to a bug in the Standard C++ Library basic_string class implementation. When assigning a shorter string to an existing string that originally contained a longer string, the heap is corrupted. The assignment can be done either through operator=() or assign().
RESOLUTION
To work around the problem, call the string::erase member function before assigning the new value to the existing string.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Visual C++ version 6.0 for Windows.
MORE INFORMATION
Steps to Reproduce Behavior
//Compile options needed: /GX #include <crtdbg.h> #include <string> int main() { std::string str, str2; str = "abcdefghijklmnopqrstuvwxyzabcdefghij" ; str2 = str; //Workaround, uncomment the following line //str.erase() ; str = "zyxw" ; _CrtCheckMemory() ; return 0; }
Keywords: kbbug kbfix kbvc600fix KB172398