From 9348da2fc0395dfe8704cb7e618f7b129f054865 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 23 Mar 2005 23:45:45 +0000 Subject: [PATCH] fixed broken wxCtime() implementation (wrong buffer size count, wrong conversion) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33008 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/wxchar.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/common/wxchar.cpp b/src/common/wxchar.cpp index 5af0fe3c94..0f8b05a3e4 100644 --- a/src/common/wxchar.cpp +++ b/src/common/wxchar.cpp @@ -1520,10 +1520,14 @@ wxStrftime(wxChar *s, size_t maxsize, const wxChar *fmt, const struct tm *tm) #ifndef wxCtime WXDLLEXPORT wxChar *wxCtime(const time_t *timep) { - static wxChar buf[128]; - - wxStrncpy( buf, wxConvertMB2WX( ctime( timep ) ), sizeof( buf ) ); - buf[ sizeof( buf ) - 1 ] = _T('\0'); + // normally the string is 26 chars but give one more in case some broken + // DOS compiler decides to use "\r\n" instead of "\n" at the end + static wxChar buf[27]; + + // ctime() is guaranteed to return a string containing only ASCII + // characters, as its format is always the same for any locale + wxStrncpy(buf, wxString::FromAscii(ctime(timep)), WXSIZEOF(buf)); + buf[WXSIZEOF(buf) - 1] = _T('\0'); return buf; } -- 2.47.2