Fixed size buffers are not a good thing. Period.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16498 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -634,19 +634,15 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
|
|||||||
|
|
||||||
path += name;
|
path += name;
|
||||||
|
|
||||||
// Needed for Unicode/Ansi conversion
|
|
||||||
char buf[500];
|
|
||||||
|
|
||||||
#if defined(HAVE_MKSTEMP)
|
#if defined(HAVE_MKSTEMP)
|
||||||
// scratch space for mkstemp()
|
// scratch space for mkstemp()
|
||||||
path += _T("XXXXXX");
|
path += _T("XXXXXX");
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
// we need to copy the path to the buffer in which mkstemp() can modify it
|
||||||
strcpy( buf, wxConvFile.cWC2MB( path ) );
|
wxCharBuffer buf(path.fn_str());
|
||||||
#else
|
|
||||||
strcpy( buf, path.c_str() );
|
// cast is safe because the string length doesn't change
|
||||||
#endif
|
int fdTemp = mkstemp( (char *)buf.data() );
|
||||||
int fdTemp = mkstemp( buf );
|
|
||||||
if ( fdTemp == -1 )
|
if ( fdTemp == -1 )
|
||||||
{
|
{
|
||||||
// this might be not necessary as mkstemp() on most systems should have
|
// this might be not necessary as mkstemp() on most systems should have
|
||||||
@@ -655,11 +651,8 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
|
|||||||
}
|
}
|
||||||
else // mkstemp() succeeded
|
else // mkstemp() succeeded
|
||||||
{
|
{
|
||||||
#if wxUSE_UNICODE
|
path = wxConvFile.cMB2WX(buf);
|
||||||
path = wxConvFile.cMB2WC( buf );
|
|
||||||
#else
|
|
||||||
path = buf;
|
|
||||||
#endif
|
|
||||||
// avoid leaking the fd
|
// avoid leaking the fd
|
||||||
if ( fileTemp )
|
if ( fileTemp )
|
||||||
{
|
{
|
||||||
@@ -676,22 +669,14 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
|
|||||||
// same as above
|
// same as above
|
||||||
path += _T("XXXXXX");
|
path += _T("XXXXXX");
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
wxCharBuffer buf(path.fn_str());
|
||||||
strcpy( buf, wxConvFile.cWC2MB( path ) );
|
if ( !mktemp( buf ) )
|
||||||
#else
|
|
||||||
strcpy( buf, path.c_str() );
|
|
||||||
#endif
|
|
||||||
if ( !mktemp( buf )
|
|
||||||
{
|
{
|
||||||
path.clear();
|
path.clear();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if wxUSE_UNICODE
|
path = wxConvFile.cMB2WX(buf);
|
||||||
path = wxConvFile.cMB2WC( buf );
|
|
||||||
#else
|
|
||||||
path = buf;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#else // !HAVE_MKTEMP (includes __DOS__)
|
#else // !HAVE_MKTEMP (includes __DOS__)
|
||||||
// generate the unique file name ourselves
|
// generate the unique file name ourselves
|
||||||
|
Reference in New Issue
Block a user