From 0b336657b1805154373d64d00292c38b213db9dc Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Mon, 17 Mar 2025 10:23:00 -0400 Subject: [PATCH] Don't negate `toff` if we've already failed This avoids calling `-` on `not_a_offset`, which is set to `minutes::min()`, which is typically the min of `long`. Due to two's complement, calling `-` on this minimum value is undefined behavior. --- include/date/date.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/date/date.h b/include/date/date.h index 79a2e9d..f70153b 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -7577,7 +7577,7 @@ from_stream(std::basic_istream& is, const CharT* fmt, } } } - if (neg) + if (neg && !is.fail()) toff = -toff; checked_set(temp_offset, toff, not_a_offset, is); command = nullptr;