The information in this article applies to:
SYMPTOMSAn access violation may result after using CString::operator+= where the string on the right hand side of the operator is an empty string. If the debug CRT libraries are installed, an Assertion Failure in Dbgheap.c line 1017 will occur. The "Sample Code" section in this article gives an example that demonstrates this problem. CAUSEThe CString implementation has been optimized in Visual C++ 4.0 to use reference counting in order to minimize duplication in allocation of memory. When operator+= is used to append an empty string, the code in CString::ConcatInPlace() incorrectly decrements the reference count. If more than one CString is pointing at this data, the call to delete in the CString destructor causes an access violation. RESOLUTIONTo work around this problem, avoid using the += operator with an empty string of the form:
Check for empty CStrings prior to appending:
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 4.1. MORE INFORMATIONSample Code
Additional query words: kbVC400bug 4.00 4.10
Keywords : kbnokeyword kbMFC kbVC kbVC410fix |
Last Reviewed: August 5, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |