[PATCH 2/4] ucrtbase: Use correct type for year with strftime format %g.

Piotr Caban piotr.caban at gmail.com
Tue Nov 26 12:43:14 CST 2019


Hi Jeff,

Could you please rename the tmp_year to something more informative? It's 
only used to store the ISO 8601 week based year now. Also I would move 
its declaration to:
case 'G':
{
     int iso_year;
...
}
It's not going to be used anywhere else (taking into account patch 4).

Thanks,
Piotr

On 11/26/19 7:00 AM, Jeff Smith wrote:
> Signed-off-by: Jeff Smith <whydoubt at gmail.com>
> ---
>   dlls/msvcrt/time.c         | 17 +++++++++++------
>   dlls/ucrtbase/tests/misc.c | 10 +++++-----
>   2 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
> index 0d5b64a4aa..50e571540f 100644
> --- a/dlls/msvcrt/time.c
> +++ b/dlls/msvcrt/time.c
> @@ -1195,6 +1195,9 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
>   {
>       MSVCRT_size_t ret, tmp;
>       BOOL alternate;
> +#if _MSVCR_VER>=140
> +    int tmp_year;
> +#endif
>       int year = mstm ? mstm->tm_year + 1900 : -1;
>   
>       if(!str || !format) {
> @@ -1323,17 +1326,19 @@ 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;
> +            tmp_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++;
> +                tmp_year--;
> +            else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(tmp_year))
> +                tmp_year++;
>               if(*format == 'G')
>               {
> -                if (!strftime_int(str, &ret, max, tmp, 4, 0, 9999))
> +                if (!strftime_int(str, &ret, max, tmp_year, 4, 0, 9999))
>                        return 0;
>               } else {
> -                if (!strftime_int(str, &ret, max, tmp%100, 2, 0, 99))
> +                if (!strftime_int(str, &ret, max, tmp_year%100, 2, 0, 99))
>                        return 0;
>               }
>               break;
> diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c
> index 8c9fc1acb0..a33742e9c1 100644
> --- a/dlls/ucrtbase/tests/misc.c
> +++ b/dlls/ucrtbase/tests/misc.c
> @@ -978,9 +978,9 @@ static void test_strftime(void)
>           {"%r", "12:00:00 AM", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE},
>           {"%r", "02:00:00 PM", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, 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},
> -        {"%g", "", { 0, 0, 0, 1, 0, -1900, 0, 0, 0 }, TRUE, FALSE, "0/" },
> +        {"%g", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }},
> +        {"%g", "", { 0, 0, 0, 1, 0, -1901, 3, 364, 0 }},
> +        {"%g", "", { 0, 0, 0, 1, 0, -1900, 0, 0, 0 }, FALSE, FALSE, "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 }},
> @@ -988,8 +988,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},
> -        {"%g", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }, 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 }},
> 




More information about the wine-devel mailing list