GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

libstdc++: Fix chrono::time_zone::get_info for very negative times [PR127815]

Fixes std::chrono::time_zone::get_info to handle very negative timestamps correctly, preventing allocation errors.

This change addresses an issue in std::chrono::time_zone::get_info where very negative timestamps could lead to incorrect calculations when subtracting info.begin. This resulted in a negative value being passed to vector::reserve, causing a length_error. The fix clamps the timestamp to prevent this issue and also modifies vector::reserve to use size_t for improved robustness against potential future negative values.

In Details

When tp - info.begin results in a negative value for a very early tp, it's passed to vector::reserve. This negative value, when converted to size_t, becomes a very large number, triggering vector::reserve's internal checks and throwing length_error. This patch clamps tp to info.begin to ensure tp - info.begin is always non-negative. Additionally, it uses size_t for the reservation size to prevent overflow in edge cases.

For Context
std::chrono::time_zone
A C++ standard library class representing a time zone, handling time conversions and daylight saving rules.
std::chrono::time_zone::get_info
A member function of std::chrono::time_zone that returns information about a specific time point within the time zone, including the start and end of daylight saving rules.
PR127815
Problem Report number 127815, indicating a bug filed against the libstdc++ library.
vector::reserve
A method of the C++ standard library's vector container that requests that the vector capacity be at least enough to contain the specified number of elements.
length_error
A standard C++ exception thrown when an arithmetic operation on container sizes results in a value too large to be represented by the container's size type.
Filed Under: libstdc++chronobugfix