don't crash in Unicode build if command line arguments are not valid UTF-8 strings (bug 1614363)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43969 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-12-13 19:03:34 +00:00
parent e6444871c1
commit 265db88d61
2 changed files with 22 additions and 5 deletions

View File

@@ -176,14 +176,23 @@ static struct InitData
static void ConvertArgsToUnicode(int argc, char **argv)
{
gs_initData.argv = new wchar_t *[argc + 1];
int wargc = 0;
for ( int i = 0; i < argc; i++ )
{
wxWCharBuffer buf(wxConvLocal.cMB2WX(argv[i]));
gs_initData.argv[i] = buf ? wxStrdup(buf) : NULL;
if ( !buf )
{
wxLogWarning(_("Command line argument %d couldn't be converted to Unicode and will be ignored."),
i);
}
else // converted ok
{
gs_initData.argv[wargc++] = wxStrdup(buf);
}
}
gs_initData.argc = argc;
gs_initData.argv[argc] = NULL;
gs_initData.argc = wargc;
gs_initData.argv[wargc] = NULL;
}
static void FreeConvertedArgs()
@@ -320,7 +329,7 @@ bool wxEntryStart(int& argc, char **argv)
{
ConvertArgsToUnicode(argc, argv);
if ( !wxEntryStart(argc, gs_initData.argv) )
if ( !wxEntryStart(gs_initData.argc, gs_initData.argv) )
{
FreeConvertedArgs();
@@ -449,7 +458,7 @@ int wxEntry(int& argc, char **argv)
{
ConvertArgsToUnicode(argc, argv);
return wxEntry(argc, gs_initData.argv);
return wxEntry(gs_initData.argc, gs_initData.argv);
}
#endif // wxUSE_UNICODE