don't crash in wxStrftime() if conversion of strftime() result to Unicode fails (modified patch 1094100)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31216 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1492,24 +1492,28 @@ int WXDLLEXPORT wxSystem(const wxChar *psz)
|
|||||||
#endif // wxNEED_WX_STDLIB_H
|
#endif // wxNEED_WX_STDLIB_H
|
||||||
|
|
||||||
#ifdef wxNEED_WX_TIME_H
|
#ifdef wxNEED_WX_TIME_H
|
||||||
WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const struct tm *tm)
|
WXDLLEXPORT size_t
|
||||||
|
wxStrftime(wxChar *s, size_t maxsize, const wxChar *fmt, const struct tm *tm)
|
||||||
{
|
{
|
||||||
if (!max) return 0;
|
if ( !maxsize )
|
||||||
|
|
||||||
char *buf = (char *)malloc(max);
|
|
||||||
size_t ret = strftime(buf, max, wxConvLocal.cWX2MB(fmt), tm);
|
|
||||||
if (ret)
|
|
||||||
{
|
|
||||||
wxStrcpy(s, wxConvLocal.cMB2WX(buf));
|
|
||||||
free(buf);
|
|
||||||
return wxStrlen(s);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
free(buf);
|
|
||||||
*s = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
wxCharBuffer buf(maxsize);
|
||||||
|
|
||||||
|
wxCharBuffer bufFmt(wxConvLocal.cWX2MB(fmt));
|
||||||
|
if ( !bufFmt )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
size_t ret = strftime(buf.data(), maxsize, bufFmt, tm);
|
||||||
|
if ( !ret )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
wxWCharBuffer wbuf = wxConvLocal.cMB2WX(buf);
|
||||||
|
if ( !wbuf )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
wxStrncpy(s, wbuf, maxsize);
|
||||||
|
return wxStrlen(s);
|
||||||
}
|
}
|
||||||
#endif // wxNEED_WX_TIME_H
|
#endif // wxNEED_WX_TIME_H
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user