BUG: Debug Assertion When Assigning to STL StringLast reviewed: August 6, 1997Article ID: Q172398 |
The information in this article applies to:
SYMPTOMSWhen 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:
Debug Error! Program <your program name> DAMAGE: after Normal block (#NNN) at 0xNNNNNNNN CAUSEThis 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().
RESOLUTIONTo workaround the problem call the string::erase member function before assigning the new value to the existing string.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
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 : STLIss Version : WINDOWS NT:5.0 Platform : NT WINDOWS Issue type : kbbug |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |