From 265db88d614412556eaf6671f442ca44d9f19b70 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 13 Dec 2006 19:03:34 +0000 Subject: [PATCH] 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 --- docs/changes.txt | 8 ++++++++ src/common/init.cpp | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 1ab190af05..4d323848a0 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -87,6 +87,14 @@ Major new features in 2.8 release wxSearchCtrl, wxAboutBox, wxTreebook, tar streams. +2.8.1 +----- + +wxGTK: + +- Don't crash if command line is not valid UTF-8 (Unicode build only) + + 2.8.0 ----- diff --git a/src/common/init.cpp b/src/common/init.cpp index e699699702..bb5693e4a9 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -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 -- 2.45.2