always NUL-terminate the buffers returned by cWC2MB/cMB2WC() overloads taking input length, even if the input is not NUL-terminated (part of patch 1795174)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48703 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -391,7 +391,10 @@ wxMBConv::cMB2WC(const char *inBuff, size_t inLen, size_t *outLen) const
|
|||||||
const size_t dstLen = ToWChar(NULL, 0, inBuff, inLen);
|
const size_t dstLen = ToWChar(NULL, 0, inBuff, inLen);
|
||||||
if ( dstLen != wxCONV_FAILED )
|
if ( dstLen != wxCONV_FAILED )
|
||||||
{
|
{
|
||||||
wxWCharBuffer wbuf(dstLen - 1);
|
// notice that we allocate space for dstLen+1 wide characters here
|
||||||
|
// because we want the buffer to always be NUL-terminated, even if the
|
||||||
|
// input isn't (as otherwise the caller has no way to know its length)
|
||||||
|
wxWCharBuffer wbuf(dstLen);
|
||||||
if ( ToWChar(wbuf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
|
if ( ToWChar(wbuf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
|
||||||
{
|
{
|
||||||
if ( outLen )
|
if ( outLen )
|
||||||
@@ -417,16 +420,18 @@ wxMBConv::cWC2MB(const wchar_t *inBuff, size_t inLen, size_t *outLen) const
|
|||||||
size_t dstLen = FromWChar(NULL, 0, inBuff, inLen);
|
size_t dstLen = FromWChar(NULL, 0, inBuff, inLen);
|
||||||
if ( dstLen != wxCONV_FAILED )
|
if ( dstLen != wxCONV_FAILED )
|
||||||
{
|
{
|
||||||
// special case of empty input: can't allocate 0 size buffer below as
|
const size_t nulLen = GetMBNulLen();
|
||||||
// wxCharBuffer insists on NUL-terminating it
|
|
||||||
wxCharBuffer buf(dstLen ? dstLen - 1 : 1);
|
// as above, ensure that the buffer is always NUL-terminated, even if
|
||||||
|
// the input is not
|
||||||
|
wxCharBuffer buf(dstLen + nulLen - 1);
|
||||||
|
memset(buf.data() + dstLen, 0, nulLen);
|
||||||
if ( FromWChar(buf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
|
if ( FromWChar(buf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
|
||||||
{
|
{
|
||||||
if ( outLen )
|
if ( outLen )
|
||||||
{
|
{
|
||||||
*outLen = dstLen;
|
*outLen = dstLen;
|
||||||
|
|
||||||
const size_t nulLen = GetMBNulLen();
|
|
||||||
if ( dstLen >= nulLen &&
|
if ( dstLen >= nulLen &&
|
||||||
!NotAllNULs(buf.data() + dstLen - nulLen, nulLen) )
|
!NotAllNULs(buf.data() + dstLen - nulLen, nulLen) )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user