This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: WG: missing TZ_LOCK
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