X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/92980e9076469956e1e2cb94df97d0f8d873114a..43a997b6e2064a189fa73ca1816908fb740ce297:/src/common/filename.cpp diff --git a/src/common/filename.cpp b/src/common/filename.cpp index b639fda809..c711152e64 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -638,9 +638,11 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) // scratch space for mkstemp() path += _T("XXXXXX"); - // can use the cast here because the length doesn't change and the string - // is not shared - int fdTemp = mkstemp((char*)(const char *)path.mb_str()); + // we need to copy the path to the buffer in which mkstemp() can modify it + wxCharBuffer buf(path.fn_str()); + + // cast is safe because the string length doesn't change + int fdTemp = mkstemp( (char *)buf.data() ); if ( fdTemp == -1 ) { // this might be not necessary as mkstemp() on most systems should have @@ -649,6 +651,8 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) } else // mkstemp() succeeded { + path = wxConvFile.cMB2WX(buf); + // avoid leaking the fd if ( fileTemp ) { @@ -665,10 +669,15 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) // same as above path += _T("XXXXXX"); - if ( !mktemp((char *)path.mb_str()) ) + wxCharBuffer buf(path.fn_str()); + if ( !mktemp( buf ) ) { path.clear(); } + else + { + path = wxConvFile.cMB2WX(buf); + } #else // !HAVE_MKTEMP (includes __DOS__) // generate the unique file name ourselves #ifndef __DOS__ @@ -1745,7 +1754,7 @@ static void MacEnsureDefaultExtensionsLoaded() { if ( !gMacDefaultExtensionsInited ) { - + // load the default extensions MacDefaultExtensionRecord defaults[1] = {