[PATCH v2 2/4] ucrtbase: Use correct type for year with strftime format %g.
Jeff Smith
whydoubt at gmail.com
Tue Nov 26 13:43:40 CST 2019
Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
dlls/msvcrt/time.c | 16 ++++++++++------
dlls/ucrtbase/tests/misc.c | 8 ++++----
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
index 0d5b64a4aa..3274fe94e6 100644
--- a/dlls/msvcrt/time.c
+++ b/dlls/msvcrt/time.c
@@ -1323,19 +1323,23 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
break;
case 'g':
case 'G':
- tmp = year;
+ if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
+ goto einval_error;
+ {
+ int iso_year = year;
if (mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4 < 0)
- tmp--;
- else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(tmp))
- tmp++;
+ iso_year--;
+ else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(iso_year))
+ iso_year++;
if(*format == 'G')
{
- if (!strftime_int(str, &ret, max, tmp, 4, 0, 9999))
+ if (!strftime_int(str, &ret, max, iso_year, 4, 0, 9999))
return 0;
} else {
- if (!strftime_int(str, &ret, max, tmp%100, 2, 0, 99))
+ if (!strftime_int(str, &ret, max, iso_year%100, 2, 0, 99))
return 0;
}
+ }
break;
#endif
case 'H':
diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c
index 9b43d73559..107bb7e84c 100644
--- a/dlls/ucrtbase/tests/misc.c
+++ b/dlls/ucrtbase/tests/misc.c
@@ -977,8 +977,8 @@ static void test_strftime(void)
{"%r", "12:00:00 AM", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE, TRUE},
{"%r", "02:00:00 PM", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, TRUE, TRUE},
{"%t", "\t", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
- {"%g", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }, TRUE},
- {"%g", "", { 0, 0, 0, 1, 0, -1901, 3, 364, 0 }, TRUE, TRUE},
+ {"%g", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }},
+ {"%g", "", { 0, 0, 0, 1, 0, -1901, 3, 364, 0 }},
{"%g", "00", { 0, 0, 0, 1, 0, -1900, 4, 0, 0 }},
{"%g", "70", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%g", "71", { 0, 0, 0, 2, 0, 72, 0, 1, 0 }},
@@ -986,8 +986,8 @@ static void test_strftime(void)
{"%g", "16", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }},
{"%g", "99", { 0, 0, 0, 1, 0, 8099, 4, 0, 0 }},
{"%g", "00", { 0, 0, 0, 1, 0, 8099, 3, 364, 0 }},
- {"%g", "", { 0, 0, 0, 1, 0, 8100, 0, 0, 0 }, TRUE, TRUE},
- {"%g", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }, TRUE, TRUE},
+ {"%g", "", { 0, 0, 0, 1, 0, 8100, 0, 0, 0 }},
+ {"%g", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }},
{"%G", "1970", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%G", "1971", { 0, 0, 0, 2, 0, 72, 0, 1, 0 }},
{"%G", "1972", { 0, 0, 0, 3, 0, 72, 1, 2, 0 }},
--
2.23.0
More information about the wine-devel
mailing list