Fix initialization of SingleCharBuffer and Utf16CharBuffer data
Don't do it at all in the ctor, initializing just the first element of the array is useless as it's overwritten by EncodeChar() anyhow, so just leave the task of NUL-terminating the data to this function as well. It might be even better to just have a ctor taking wxUniChar in these classes instead and make EncodeChar() a trivial wrapper around it, but for now just apply the minimal fix to repair the test breakage after the last commit. See https://github.com/wxWidgets/wxWidgets/pull/467#issuecomment-310384946
This commit is contained in:
@@ -48,14 +48,8 @@ struct WXDLLIMPEXP_BASE wxStringOperationsWchar
|
|||||||
// encodes the characters as UTF-16:
|
// encodes the characters as UTF-16:
|
||||||
struct Utf16CharBuffer
|
struct Utf16CharBuffer
|
||||||
{
|
{
|
||||||
Utf16CharBuffer()
|
// Notice that data is left uninitialized, it is filled by EncodeChar()
|
||||||
{
|
// which is the only function creating objects of this class.
|
||||||
// Can't rely on default initialization of the member array, it
|
|
||||||
// doesn't work at all in very old compilers and works, but warns
|
|
||||||
// about working correctly (!) in even recent versions of MSVC
|
|
||||||
// (warning C4351), so do it manually.
|
|
||||||
data[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
wchar_t data[3];
|
wchar_t data[3];
|
||||||
operator const wchar_t*() const { return data; }
|
operator const wchar_t*() const { return data; }
|
||||||
@@ -69,12 +63,6 @@ struct WXDLLIMPEXP_BASE wxStringOperationsWchar
|
|||||||
// representation
|
// representation
|
||||||
struct SingleCharBuffer
|
struct SingleCharBuffer
|
||||||
{
|
{
|
||||||
SingleCharBuffer()
|
|
||||||
{
|
|
||||||
// See comment above.
|
|
||||||
data[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxChar data[2];
|
wxChar data[2];
|
||||||
operator const wxChar*() const { return data; }
|
operator const wxChar*() const { return data; }
|
||||||
};
|
};
|
||||||
@@ -82,6 +70,7 @@ struct WXDLLIMPEXP_BASE wxStringOperationsWchar
|
|||||||
{
|
{
|
||||||
SingleCharBuffer buf;
|
SingleCharBuffer buf;
|
||||||
buf.data[0] = (wxChar)ch;
|
buf.data[0] = (wxChar)ch;
|
||||||
|
buf.data[1] = 0;
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
static wxWxCharBuffer EncodeNChars(size_t n, const wxUniChar& ch);
|
static wxWxCharBuffer EncodeNChars(size_t n, const wxUniChar& ch);
|
||||||
|
@@ -38,11 +38,13 @@ wxStringOperationsWchar::Utf16CharBuffer wxStringOperationsWchar::EncodeChar(con
|
|||||||
{
|
{
|
||||||
buf.data[0] = (wchar_t)ch.HighSurrogate();
|
buf.data[0] = (wchar_t)ch.HighSurrogate();
|
||||||
buf.data[1] = (wchar_t)ch.LowSurrogate();
|
buf.data[1] = (wchar_t)ch.LowSurrogate();
|
||||||
|
buf.data[2] = L'\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Assume ch is a BMP character
|
// Assume ch is a BMP character
|
||||||
buf.data[0] = (wchar_t)ch;
|
buf.data[0] = (wchar_t)ch;
|
||||||
|
buf.data[1] = L'\0';
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user