Kaben123 opened a new pull request, #21921:
URL: https://github.com/apache/nuttx/pull/21921
## Summary
Two fixes for POSIX TZ string handling in `libs/libc/time/lib_localtime.c`:
1. **initialize goback/goahead in tzparse()**: only the DST-rule branch of
`tzparse()` set `goback`/`goahead`. When a TZ string is parsed into a
non-zeroed `state_s` from `lib_malloc()`, the other branches leave heap
garbage in these fields, and `localsub()` then applies a bogus wrap-around
now and then (wrong hour in `localtime()`/`mktime()`).
2. **fix DST transitions without zoneinfo**: without
`CONFIG_LIBC_ZONEINFO`, `atlo` stays at `TIME_T_MIN`, so the POSIX-rule
transition generator starts around 1770 and fills `TZ_MAX_TIMES` around
1954. Modern timestamps get no DST transitions, so DST is silently
ignored.
`atlo` is now clamped to the Unix epoch when no base rules are loaded.
## Impact
Only affects `CONFIG_LIBC_LOCALTIME`. With a POSIX TZ string and no zoneinfo
database, `localtime()`/`mktime()` now apply DST correctly. No API or
Kconfig change.
## Testing
Host: Ubuntu 22.04 x86_64, GCC 13.1.0. Base: apache/nuttx master
5c1746778e8, apache/nuttx-apps master 7f4e5382d.
`sim:nsh` + `CONFIG_LIBC_LOCALTIME=y` (no zoneinfo),
TZ=`EST5EDT,M3.2.0,M11.1.0`.
Local time is set with `date -s` and read back as UTC with `date -u`.
July should be UTC-4 (EDT), January UTC-5 (EST).
Before (master), July is wrong (DST ignored):
```
nsh> set TZ EST5EDT,M3.2.0,M11.1.0
nsh> date -s "Jul 01 12:00:00 2026"
nsh> date
Wed, Jul 01 12:00:00 2026
nsh> date -u
Wed, Jul 01 17:00:00 2026
nsh> date -s "Jan 15 12:00:00 2026"
nsh> date
Thu, Jan 15 12:00:00 2026
nsh> date -u
Thu, Jan 15 17:00:00 2026
nsh> poweroff
```
After:
```
nsh> set TZ EST5EDT,M3.2.0,M11.1.0
nsh> date -s "Jul 01 12:00:00 2026"
nsh> date
Wed, Jul 01 12:00:00 2026
nsh> date -u
Wed, Jul 01 16:00:00 2026
nsh> date -s "Jan 15 12:00:00 2026"
nsh> date
Thu, Jan 15 12:00:00 2026
nsh> date -u
Thu, Jan 15 17:00:00 2026
nsh> poweroff
```
`tools/checkpatch.sh -c -u -m -g` passes. `sim:nsh` builds with CMake and
Make without new warnings.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]