Tim,
Looking at the VS2005 B2 source code, it has been changed from the
VS2003 code. The relevant part of the Init method now looks like this:
int nLengthA = nLengthW*4;
AtlConvAllocMemory(&m_psz,nLengthA,m_szBuffer,t_nBufferLength);
BOOL bFailed=(0 == ::WideCharToMultiByte( nCodePage, 0, psz, nLengthW,
m_psz, nLengthA, NULL, NULL ));
if (bFailed)
{
if (GetLastError()==ERROR_INSUFFICIENT_BUFFER)
{
nLengthA = ::WideCharToMultiByte( nCodePage, 0, psz,
nLengthW, NULL, 0, NULL, NULL );
AtlConvAllocMemory(&m_psz,nLengthA,m_szBuffer,t_nBufferLength);
bFailed=(0 == ::WideCharToMultiByte( nCodePage, 0,
psz, nLengthW, m_psz, nLengthA, NULL, NULL ));
}
}
Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
It's not that bad - codepoints that require 4 bytes in UTF-8 also
require 2 WCHARs in UTF-16 (which is what is meant by Unicode in Win32
API). Your point is still valid of course - some 16-bit codepoints
require 3 bytes in UTF-8, and those would overflow the buffer.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
It's bug in ATL. I remember reporting it some time ago, in company where
I work we have been working on patched version for a long time now (our
code has hit that issue when converting Chinese text into utf-8). Nice
to hear (in some other mail) vs2005 finally fixed it.
Maciej Mróz