Don't return a dangling pointer from wxDateTime::ParseXXX(wxCStrData).

We don't have any sufficiently long-lived pointer to return from this
overload, so don't return anything from it -- it's better to break the
compilation of the existing code rather than make it crash during run-time.

Closes #14214.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71430 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-05-13 21:37:25 +00:00
parent 2ed48ef81e
commit ae8079a210
2 changed files with 26 additions and 12 deletions

View File

@ -285,6 +285,12 @@ Changes in behaviour which may result in compilation errors
error instead. This can be worked around by explicitly casting to const
wxChar*: wxLogError(_("error: %s"), !err.empty() ? (const wxChar*)err.c_str() : "")
- wxDateTime::ParseXXX() overloads don't return anything when called with
wxCStrData argument. If you need to test the parsing success, use a newer
overload taking wxString::const_iterator and returning bool or explicitly
select a narrow or wide char version to use by casting c_str() to either
"char*" or "wchar_t*". Or create a temporary wxString and parse it instead.
- wxCtime() and wxAsctime() return char*; this is incompatible with Unicode
build in wxWidgets 2.8 that returned wchar_t*.

View File

@ -1211,15 +1211,23 @@ public:
// if the overloads above were used.
//
// And then we also have to provide the overloads for wxCStrData, as usual.
wxAnyStrPtr ParseRfc822Date(const wxCStrData& date)
{ return ParseRfc822Date(wxString(date)); }
// Unfortunately those ones can't return anything as we don't have any
// sufficiently long-lived wxAnyStrPtr to return from them: any temporary
// strings it would point to would be destroyed when this function returns
// making it impossible to dereference the return value. So we just don't
// return anything from here which at least allows to keep compatibility
// with the code not testing the return value. Other uses of this method
// need to be converted to use one of the new bool-returning overloads
// above.
void ParseRfc822Date(const wxCStrData& date)
{ ParseRfc822Date(wxString(date)); }
const char* ParseRfc822Date(const char* date);
const wchar_t* ParseRfc822Date(const wchar_t* date);
wxAnyStrPtr ParseFormat(const wxCStrData& date,
const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime)
{ return ParseFormat(wxString(date), format, dateDef); }
void ParseFormat(const wxCStrData& date,
const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime)
{ ParseFormat(wxString(date), format, dateDef); }
const char* ParseFormat(const char* date,
const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime);
@ -1227,18 +1235,18 @@ public:
const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime);
wxAnyStrPtr ParseDateTime(const wxCStrData& datetime)
{ return ParseDateTime(wxString(datetime)); }
void ParseDateTime(const wxCStrData& datetime)
{ ParseDateTime(wxString(datetime)); }
const char* ParseDateTime(const char* datetime);
const wchar_t* ParseDateTime(const wchar_t* datetime);
wxAnyStrPtr ParseDate(const wxCStrData& date)
{ return ParseDate(wxString(date)); }
void ParseDate(const wxCStrData& date)
{ ParseDate(wxString(date)); }
const char* ParseDate(const char* date);
const wchar_t* ParseDate(const wchar_t* date);
wxAnyStrPtr ParseTime(const wxCStrData& time)
{ return ParseTime(wxString(time)); }
void ParseTime(const wxCStrData& time)
{ ParseTime(wxString(time)); }
const char* ParseTime(const char* time);
const wchar_t* ParseTime(const wchar_t* time);