Don't crash on trailing '%' in wxDateTime::Format(). See #17931
This commit is contained in:
@@ -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__
|
||||
|
@@ -822,6 +822,8 @@ void DateTimeTestCase::TestTimeFormat()
|
||||
}
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT(wxDateTime::Now().Format("%") == "%");
|
||||
|
||||
wxDateTime dt;
|
||||
|
||||
#if 0
|
||||
|
Reference in New Issue
Block a user