From 27d1e1e54e4d120f421710df2040f54d51527c21 Mon Sep 17 00:00:00 2001 From: tomaszkam Date: Tue, 28 May 2019 15:01:14 +0200 Subject: [PATCH] Removed undefined behavioir from year_mont_day_last::day (#456) This is done to make the result of calling day() on year_month_day_last object that is !ok() unspecified. Checked only months, are there are needed to avoid UB. --- include/date/date.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/date/date.h b/include/date/date.h index d99332b..4e1e3f3 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -7,7 +7,7 @@ // Copyright (c) 2016 Adrian Colomitchi // Copyright (c) 2017 Florian Dang // Copyright (c) 2017 Paul Thompson -// Copyright (c) 2018 Tomasz Kamiński +// Copyright (c) 2018, 2019 Tomasz Kamiński // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -2536,7 +2536,7 @@ year_month_day_last::day() const NOEXCEPT date::day(31), date::day(31), date::day(30), date::day(31), date::day(30), date::day(31) }; - return month() != February || !y_.is_leap() ? + return (month() != February || !y_.is_leap()) && mdl_.ok() ? d[static_cast(month()) - 1] : date::day{29}; }