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();
|
time_t time = GetTicks();
|
||||||
|
|
||||||
bool canUseStrftime = time != (time_t)-1;
|
bool canUseStrftime = time != (time_t)-1;
|
||||||
|
bool isPercent = false;
|
||||||
|
|
||||||
// We also can't use strftime() if we use non standard specifier: either
|
// 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
|
// 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();
|
canUseStrftime && p != format.end();
|
||||||
++p )
|
++p )
|
||||||
{
|
{
|
||||||
if ( *p != '%' )
|
if (!isPercent)
|
||||||
|
{
|
||||||
|
isPercent = *p == '%';
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
isPercent = false;
|
||||||
|
|
||||||
// set the default format
|
// set the default format
|
||||||
switch ( (*++p).GetValue() )
|
switch ( (*p).GetValue() )
|
||||||
{
|
{
|
||||||
case 'l':
|
case 'l':
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
@@ -822,6 +822,8 @@ void DateTimeTestCase::TestTimeFormat()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(wxDateTime::Now().Format("%") == "%");
|
||||||
|
|
||||||
wxDateTime dt;
|
wxDateTime dt;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
Reference in New Issue
Block a user