Re: `mktime` bug in arm-none-eabi-newlib-4.5.0.20241231-1

"Richard Earnshaw (lists)" <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On 25/02/2025 18:15, Gerald Wisböck wrote:
> Hi,
> Using `mktime` in arm-none-eabi-newlib-4.5.0.20241231-1 causes a hardfault.
> 
> I assume it is related to the extraneous `_tzset_unlocked ();` call.

It's not extraneous, it's needed to correctly set variables such as _daylight, which are used in the subseqent code, based on the current timezone.  We used the 'unlocked' call because we have already taken the lock and need to ensure that any other threads (if they exist) won't change those settings while the calculations are done.

> 
> ```c
> /* compute total seconds */
>   tim += (time_t)days * _SEC_IN_DAY;
> 
>   TZ_LOCK;
> 
>   _tzset_unlocked (); // This call is bad. I believe only TZ_LOCK/TZ_UNLOCK macros should be used if intentional.
> 
>   if (_daylight)
>   <stuff>
>   TZ_UNLOCK; // unlock should happen here
>   <stuff>
> ```
> 
> Another user seems to have encountered this issue: https://stackoverflow.com/a/63367315/4479969
> 
> Is this already fixed?

You'll need to show more detail of what's failing for you.  Almost certainly it's not related directly to this code, but to something else in your environment.  Is the heap correctly set up, for example, or is getenv not working correctly?

A gdb backtrace might be a start, but a reduced testcase that somebody can use to replicate and investigate the problem properly would be even better.

> Can you release a hotfix?
> 
> Kind regards,
> raldone01

R.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.