FIX: Debug Assertion When Assigning to STL String (172398)
The information in this article applies to:
- The Standard C++ Library, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
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:
Debug Error!
Program <your program name>
DAMAGE: after Normal block (#NNN) at 0xNNNNNNNN
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.
Modification Type: | Major | Last Reviewed: | 11/18/2003 |
---|
Keywords: | kbBug kbfix kbVC600fix KB172398 |
---|
|