- size_t lenAnsi = tool->m_shortHelpString.Len();
- size_t lenUnicode = mbstowcs(NULL, tool->m_shortHelpString, lenAnsi);
- wchar_t *pwz = new wchar_t[lenUnicode + 1];
- mbstowcs(pwz, tool->m_shortHelpString, lenAnsi + 1);
- memcpy(ttText->szText, pwz,
- (sizeof(ttText->szText) - 1)/sizeof(ttText->szText[0]));
- ttText->szText[WXSIZEOF(ttText->szText)] = 0;
+
+ size_t lenAnsi = help.Len();
+ #ifdef __MWERKS__
+ // MetroWerks doesn't like calling mbstowcs with NULL argument
+ size_t lenUnicode = 2*lenAnsi;
+ #else
+ size_t lenUnicode = mbstowcs(NULL, help, lenAnsi);
+ #endif
+
+ // using the pointer of right type avoids us doing all sorts of
+ // pointer arithmetics ourselves
+ wchar_t *dst = (wchar_t *)ttText->szText,
+ *pwz = new wchar_t[lenUnicode + 1];
+ mbstowcs(pwz, help, lenAnsi + 1);
+ memcpy(dst, pwz, lenUnicode*sizeof(wchar_t));
+
+ // put the terminating _wide_ NUL
+ dst[lenUnicode] = 0;