Don't crash on trailing '%' in wxDateTime::Format(). See #17931

This commit is contained in:
Paul Cornett
2017-08-01 08:35:58 -07:00
parent 1eef3fc5fc
commit 3a9fc640e4
2 changed files with 9 additions and 2 deletions

View File

@@ -334,6 +334,7 @@ wxString wxDateTime::Format(const wxString& formatp, const TimeZone& tz) const
time_t time = GetTicks();
bool canUseStrftime = time != (time_t)-1;
bool isPercent = false;
// We also can't use strftime() if we use non standard specifier: either
// our own extension "%l" or one of "%g", "%G", "%V", "%z" which are POSIX
@@ -342,11 +343,15 @@ wxString wxDateTime::Format(const wxString& formatp, const TimeZone& tz) const
canUseStrftime && p != format.end();
++p )
{
if ( *p != '%' )
if (!isPercent)
{
isPercent = *p == '%';
continue;
}
isPercent = false;
// set the default format
switch ( (*++p).GetValue() )
switch ( (*p).GetValue() )
{
case 'l':
#ifdef __WINDOWS__

View File

@@ -822,6 +822,8 @@ void DateTimeTestCase::TestTimeFormat()
}
}
CPPUNIT_ASSERT(wxDateTime::Now().Format("%") == "%");
wxDateTime dt;
#if 0