fixed compilation in non-Unicode build; fixed bug with buffer overrun in wxMBConvUTF8::MB2WC()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33109 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -615,6 +615,8 @@ size_t wxMBConvUTF7::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
static wxUint32 utf8_max[]=
|
||||
{ 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff, 0xffffffff };
|
||||
|
||||
// boundaries of the private use area we use to (temporarily) remap invalid
|
||||
// characters invalid in a UTF-8 encoded string
|
||||
const wxUint32 wxUnicodePUA = 0x100000;
|
||||
const wxUint32 wxUnicodePUAEnd = wxUnicodePUA + 256;
|
||||
|
||||
@@ -718,26 +720,23 @@ size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
if (m_options & MAP_INVALID_UTF8_TO_OCTAL)
|
||||
else if (m_options & MAP_INVALID_UTF8_TO_OCTAL)
|
||||
{
|
||||
while (opsz < psz && (!buf || len < n))
|
||||
{
|
||||
wchar_t str[6];
|
||||
wxSnprintf( str, 5, L"\\%o", (int) (unsigned char) *opsz );
|
||||
if (buf)
|
||||
*buf++ = str[0];
|
||||
if (buf)
|
||||
*buf++ = str[1];
|
||||
if (buf)
|
||||
*buf++ = str[2];
|
||||
if (buf)
|
||||
*buf++ = str[3];
|
||||
if ( buf && len + 3 < n )
|
||||
{
|
||||
unsigned char n = *opsz;
|
||||
*buf++ = L'\\';
|
||||
*buf++ = L'0' + n / 0100;
|
||||
*buf++ = L'0' + (n % 0100) / 010;
|
||||
*buf++ = L'0' + n % 010;
|
||||
}
|
||||
opsz++;
|
||||
len += 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
else // MAP_INVALID_UTF8_NOT
|
||||
{
|
||||
return (size_t)-1;
|
||||
}
|
||||
@@ -749,6 +748,11 @@ size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
return len;
|
||||
}
|
||||
|
||||
static inline bool isoctal(wchar_t wch)
|
||||
{
|
||||
return L'0' <= wch && wch <= L'7';
|
||||
}
|
||||
|
||||
size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
size_t len = 0;
|
||||
@@ -763,6 +767,7 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
#else
|
||||
cc=(*psz++) & 0x7fffffff;
|
||||
#endif
|
||||
|
||||
if ( (m_options & MAP_INVALID_UTF8_TO_PUA)
|
||||
&& cc >= wxUnicodePUA && cc < wxUnicodePUAEnd )
|
||||
{
|
||||
@@ -770,19 +775,18 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
*buf++ = (char)(cc - wxUnicodePUA);
|
||||
len++;
|
||||
}
|
||||
else
|
||||
if ((m_options & MAP_INVALID_UTF8_TO_OCTAL)
|
||||
&& cc == L'\\')
|
||||
else if ( (m_options & MAP_INVALID_UTF8_TO_OCTAL) &&
|
||||
cc == L'\\' &&
|
||||
isoctal(psz[0]) && isoctal(psz[1]) && isoctal(psz[2]) )
|
||||
{
|
||||
wchar_t str[4];
|
||||
str[0] = *psz; psz++;
|
||||
str[1] = *psz; psz++;
|
||||
str[2] = *psz; psz++;
|
||||
str[3] = 0;
|
||||
int octal;
|
||||
wxSscanf( str, L"%o", &octal );
|
||||
if (buf)
|
||||
*buf++ = (char) octal;
|
||||
{
|
||||
*buf++ = (char) (psz[0] - L'0')*0100 +
|
||||
(psz[1] - L'0')*010 +
|
||||
(psz[2] - L'0');
|
||||
}
|
||||
|
||||
psz += 3;
|
||||
len++;
|
||||
}
|
||||
else
|
||||
@@ -810,7 +814,8 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
}
|
||||
}
|
||||
|
||||
if (buf && (len<n)) *buf = 0;
|
||||
if (buf && (len<n))
|
||||
*buf = 0;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
Reference in New Issue
Block a user