Correct wxConvAuto::ToWChar() behaviour with wxNO_LEN input size.
We didn't handle the case when the length of the input buffer was not specified correctly and wxConvAuto::DetectBOM() could read beyond the end of input. Moreover, the unit test actually relied on this as it didn't pass the correct length for the literal strings with embedded NULs. This somehow worked with MSVC but failed with MinGW (see #10713). Correct the code to handle wxNO_LEN case correctly and fix the unit test to pass the correct lengths. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65739 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
051d655703
commit
9334ad1727
@ -229,7 +229,7 @@ void wxConvAuto::SkipBOM(const char **src, size_t *len) const
|
||||
|
||||
bool wxConvAuto::InitFromInput(const char *src, size_t len)
|
||||
{
|
||||
m_bomType = DetectBOM(src, len);
|
||||
m_bomType = DetectBOM(src, len == wxNO_LEN ? strlen(src) : len);
|
||||
if ( m_bomType == BOM_Unknown )
|
||||
return false;
|
||||
|
||||
|
@ -51,7 +51,10 @@ private:
|
||||
|
||||
// real test function: check that converting the src multibyte string to
|
||||
// wide char using wxConvAuto yields wch as the first result
|
||||
void TestFirstChar(const char *src, wchar_t wch);
|
||||
//
|
||||
// the length of the string may need to be passed explicitly if it has
|
||||
// embedded NULs, otherwise it's not necessary
|
||||
void TestFirstChar(const char *src, wchar_t wch, int len = wxNO_LEN);
|
||||
|
||||
void Empty();
|
||||
void Short();
|
||||
@ -86,16 +89,16 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConvAutoTestCase, "ConvAutoTestCase");
|
||||
// tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ConvAutoTestCase::TestFirstChar(const char *src, wchar_t wch)
|
||||
void ConvAutoTestCase::TestFirstChar(const char *src, wchar_t wch, int len)
|
||||
{
|
||||
wxWCharBuffer wbuf = wxConvAuto().cMB2WC(src);
|
||||
wxWCharBuffer wbuf = wxConvAuto().cMB2WC(src, len, NULL);
|
||||
CPPUNIT_ASSERT( wbuf );
|
||||
CPPUNIT_ASSERT_EQUAL( wch, *wbuf );
|
||||
}
|
||||
|
||||
void ConvAutoTestCase::Empty()
|
||||
{
|
||||
TestFirstChar("", wxT('\0'));
|
||||
CPPUNIT_ASSERT( !wxConvAuto().cMB2WC("") );
|
||||
}
|
||||
|
||||
void ConvAutoTestCase::Short()
|
||||
@ -110,22 +113,22 @@ void ConvAutoTestCase::None()
|
||||
|
||||
void ConvAutoTestCase::UTF32LE()
|
||||
{
|
||||
TestFirstChar("\xff\xfe\0\0A\0\0\0", wxT('A'));
|
||||
TestFirstChar("\xff\xfe\0\0A\0\0\0", wxT('A'), 8);
|
||||
}
|
||||
|
||||
void ConvAutoTestCase::UTF32BE()
|
||||
{
|
||||
TestFirstChar("\0\0\xfe\xff\0\0\0B", wxT('B'));
|
||||
TestFirstChar("\0\0\xfe\xff\0\0\0B", wxT('B'), 8);
|
||||
}
|
||||
|
||||
void ConvAutoTestCase::UTF16LE()
|
||||
{
|
||||
TestFirstChar("\xff\xfeZ\0", wxT('Z'));
|
||||
TestFirstChar("\xff\xfeZ\0", wxT('Z'), 4);
|
||||
}
|
||||
|
||||
void ConvAutoTestCase::UTF16BE()
|
||||
{
|
||||
TestFirstChar("\xfe\xff\0Y", wxT('Y'));
|
||||
TestFirstChar("\xfe\xff\0Y", wxT('Y'), 4);
|
||||
}
|
||||
|
||||
void ConvAutoTestCase::UTF8()
|
||||
|
Loading…
Reference in New Issue
Block a user