WG: missing TZ_LOCK
Corinna Vinschen
vinschen@redhat.com
Tue Jun 28 10:11:00 GMT 2011
On Jun 27 10:54, Becker, Andreas wrote:
> Hi Folks,
>
> We are using the localtime, mktime - Â functions really heavy. Sometimes a miscalculation happened.
> With hard investigations, we could verify that the problem is a missing lock around the global __tzinfo_type *tz structure. Â
> This structure is returned by __gettzinfo() and changed by __tz_calc_limits(year) .
> Operations on this structure should be protected by TZ_LOCK() and TZ_UNLOCK().
> This is correctly done in (newlib/time/) mktm_r.c, tzset_r.c and strftime.c but missing in mktime.c
>
> --- a/newlib/libc/time/mktime.c Mon Jun 28 11:00:35 2010 +0200
> +++ b/newlib/libc/time/mktime.c Mon Jun 27 10:18:58 2011 +0200
> @@ -204,6 +204,8 @@
>
> Â Â Â isdst = tim_p->tm_isdst;
>
> +Â TZ_LOCK;
> +Â Â Â
> Â Â Â if (_daylight)
> Â Â Â Â {
> Â Â Â Â Â Â int y = tim_p->tm_year + YEAR_BASE;
> @@ -251,6 +253,8 @@
> Â Â else /* otherwise assume std time */
> Â Â Â Â tim += (time_t) tz->__tzrule[0].offset;
>
> +Â TZ_UNLOCK;
> +Â
> Â Â Â /* reset isdst flag to what we have calculated */
> Â Â tim_p->tm_isdst = isdst;
Thanks for catching this. I applied your patch.
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat
More information about the Newlib
mailing list