On Tue, 13 Oct 2026 at 21:09, Jonathan Wakely wrote:
>
> A very negative time point will stay negative when info.begin is
> subtracted from it, which means that a negative value will be passed to
> vector::reserve. That will convert to a huge size_t value, and the
> vector will throw length_error. This commit clamps the time point
> argument to be no less than the start of the zone's first info, so that
> `tp - info.begin` will be non-negative.
>
> This commit also changes it to chrono::abs(tp - info.begin).  This is
> not strictly necessary now that tp is not less than info.begin, but it
> makes the code more robust. Even if a later change makes it possible for
> the value to be negative again, we will not pass a negative value to
> vector::reserve.
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/127815
>         * src/c++20/tzdb.cc (time_zone::_M_get_sys_info): Clamp
>         parameter to start of first info. Use chrono::abs for argument
>         to vector::reserve.
>         * testsuite/std/time/time_zone/127815.cc: New test.

gcc.sashiko.dev made some useful comments on this patch
https://gcc.sashiko.dev/#/patchset/20261013200857.3698160-1-jwakely%40redhat.com

Reply via email to