This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: strptime() could hangs for hours
- From: Corinna Vinschen <vinschen at redhat dot com>
- To: newlib at sourceware dot org
- Date: Mon, 14 Feb 2011 14:06:22 +0100
- Subject: Re: strptime() could hangs for hours
- References: <1297672912.4359.51.camel@manwe.oktetlabs.ru>
- Reply-to: newlib at sourceware dot org
On Feb 14 11:41, Aleksandr Platonov wrote:
> Hi,
> strptime() function could hangs if format string contains characters
> which set date by week number (U,W,V).
> Example:
> struct tm tm;
> tm.tm_year = 0x6FFFFFFF;
> strptime("52", "%U", &tm);
>
> This happens because first_day() function call hangs for hours if big
> year value is passed to it.
> We could not assume that tm_year field of tm structure has correct value
> at processing U,V,W characters in strptime(), so first_day() function
> parameter could have any value.
> In BSD libc characters U,V and W are ignored (only range check is
> performed).
> Is this behaviour of strptime() in newlib correct?
No, it's not. Probably the right thing to do would be to store the
information that U,V,W is present together with the given week number,
and to calculate the information when the string has been completely
scanned and we only have a valid year, but no day or month. Or,
as on BSD, ignore the input and just check validity.
Does anybody want to provide a patch?
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat