From a817d76af415f3bd24509bde659cd76dd71d1043 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 29 Dec 2025 23:33:39 +0300 Subject: [PATCH] cron::cron_next : check cronexpr initialized to avoid endless recursion --- include/croncpp.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/croncpp.h b/include/croncpp.h index b0037c0..8526e57 100644 --- a/include/croncpp.h +++ b/include/croncpp.h @@ -210,6 +210,8 @@ namespace cron friend std::string to_cronstr(cronexpr const& cex); friend std::string to_string(cronexpr const & cex); + friend bool is_initialized(cronexpr const& cex); + template friend cronexpr make_cron(CRONCPP_STRING_VIEW expr); }; @@ -230,6 +232,10 @@ namespace cron return !(e1 == e2); } + inline bool is_initialized(cronexpr const& cex ){ + return !cex.expr.empty(); + } + inline std::string to_string(cronexpr const & cex) { return @@ -865,6 +871,8 @@ namespace cron template static std::tm cron_next(cronexpr const & cex, std::tm date) { + if(!is_initialized(cex)) + throw bad_cronexpr("Cron expr is not initialized"); time_t original = utils::tm_to_time(date); if (INVALID_TIME == original) return {}; @@ -887,6 +895,8 @@ namespace cron template static std::time_t cron_next(cronexpr const & cex, std::time_t const & date) { + if(!is_initialized(cex)) + throw bad_cronexpr("Cron expr is not initialized"); std::tm val; std::tm* dt = utils::time_to_tm(&date, &val); if (dt == nullptr) return INVALID_TIME;