According to the MSDN documentation for CString GetBufferSetLength(), a call to this method must be followed by a corresponding call ReleaseBuffer().
However, in the code example on the same page, the comment indicates that the call is ReleaseBuffer()not needed:
CSimpleString str(pMgr);
LPTSTR pstr = str.GetBufferSetLength(3);
pstr[0] = _T('C');
pstr[1] = _T('u');
pstr[2] = _T('p');
// No need for trailing zero or call to ReleaseBuffer()
// because GetBufferSetLength() set it for us.
str += _T(" soccer is best!");
ASSERT(_tcscmp(str, _T("Cup soccer is best!")) == 0);
So, should you fix the code call ReleaseBuffer()after GetBufferSetLength(), or is this call superfluous?
EDIT
According to several tests that I have done, it sounds like a call is ReleaseBuffer()not needed after GetBufferSetLength(), but:
- Those tests are not complete.
- I am interested in writing the correct code in accordance with the official specifications of the CString interface, and not implementation-dependent code that may work on this version of VS, and then crash on the next one.