From f99ff49e29fc70c0063ef91898bf7e7d90999f4e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 14 Oct 2014 19:36:46 +0000 Subject: [PATCH] Don't end converting prematurely on encountering consecutive NULs. Don't stop converting subsequent chunks just because the length of one of them was 0: this can happen if the first character of a string is a NUL or if there are two (or more) NULs in it later. Simply remove the check for this and continue as usual even in this case. Also add a unit test verifying that we do translate NULs in input into NULs in output. Closes #16620. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78021 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/strconv.cpp | 6 ------ tests/strings/unicode.cpp | 4 ++++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index af447aa631..949f2a71ec 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -232,12 +232,6 @@ wxMBConv::ToWChar(wchar_t *dst, size_t dstLen, if ( !srcEnd ) dstWritten++; - if ( !lenChunk ) - { - // nothing left in the input string, conversion succeeded - break; - } - if ( dst ) { if ( dstWritten > dstLen ) diff --git a/tests/strings/unicode.cpp b/tests/strings/unicode.cpp index 5f2e9dec65..edec58bc19 100644 --- a/tests/strings/unicode.cpp +++ b/tests/strings/unicode.cpp @@ -291,6 +291,10 @@ void UnicodeTestCase::ConversionWithNULs() CPPUNIT_ASSERT( memcmp(theLocalBuffer.data(), L"The\0String", 11 * sizeof(wchar_t)) == 0 ); #endif // wxUSE_UNICODE/!wxUSE_UNICODE + + const char *null4buff = "\0\0\0\0"; + wxString null4str(null4buff, 4); + CPPUNIT_ASSERT_EQUAL( 4, null4str.length() ); } void UnicodeTestCase::ConversionUTF7()