for ( const char *p = src; ; p++ )
{
- if ( !(srcLen == wxNO_LEN ? *p : srcLen) )
+ if ( (srcLen == wxNO_LEN ? !*p : !srcLen) )
{
// all done successfully, just add the trailing NULL if we are not
// using explicit length
for ( const wchar_t *wp = src; ; wp++ )
{
- if ( !(srcLen == wxNO_LEN ? *wp : srcLen) )
+ if ( (srcLen == wxNO_LEN ? !*wp : !srcLen) )
{
// all done successfully, just add the trailing NULL if we are not
// using explicit length
size_t len = 0;
- while ((srcLen == wxNO_LEN ? *psz : srcLen--) && ((!buf) || (len < n)))
+ // The length can be either given explicitly or computed implicitly for the
+ // NUL-terminated strings.
+ const bool isNulTerminated = srcLen == wxNO_LEN;
+ while ((isNulTerminated ? *psz : srcLen--) && ((!buf) || (len < n)))
{
const char *opsz = psz;
bool invalid = false;
}
}
- if (srcLen == wxNO_LEN && buf && (len < n))
- *buf = 0;
+ if ( isNulTerminated )
+ {
+ // Add the trailing NUL in this case if we have a large enough buffer.
+ if ( buf && (len < n) )
+ *buf = 0;
- return len + 1;
+ // And count it in any case.
+ len++;
+ }
+
+ return len;
}
static inline bool isoctal(wchar_t wch)
wxUint16 *outBuff = reinterpret_cast<wxUint16 *>(dst);
for ( size_t n = 0; n < srcLen; n++ )
{
- wxUint16 cc[2];
+ wxUint16 cc[2] = { 0 };
const size_t numChars = encode_utf16(*src++, cc);
if ( numChars == wxCONV_FAILED )
return wxCONV_FAILED;
wxUint16 *outBuff = reinterpret_cast<wxUint16 *>(dst);
for ( const wchar_t *srcEnd = src + srcLen; src < srcEnd; src++ )
{
- wxUint16 cc[2];
+ wxUint16 cc[2] = { 0 };
const size_t numChars = encode_utf16(*src, cc);
if ( numChars == wxCONV_FAILED )
return wxCONV_FAILED;
size_t outLen = 0;
for ( size_t n = 0; n < inLen; n++ )
{
- wxUint16 cc[2];
+ wxUint16 cc[2] = { 0 };
const size_t numChars = encode_utf16(*inBuff++, cc);
if ( numChars == wxCONV_FAILED )
return wxCONV_FAILED;
size_t outLen = 0;
for ( size_t n = 0; n < inLen; n++, inBuff++ )
{
- wxUint16 cc[2];
+ wxUint16 cc[2] = { 0 };
const size_t numChars = encode_utf16(wxUINT32_SWAP_ALWAYS(*inBuff), cc);
if ( numChars == wxCONV_FAILED )
return wxCONV_FAILED;
{
#if SIZEOF_WCHAR_T == 4
wxT("UCS-4"),
-#elif SIZEOF_WCHAR_T = 2
+#elif SIZEOF_WCHAR_T == 2
wxT("UCS-2"),
#endif
NULL