Skip to content

Commit 4899c91

Browse files
committed
refactor: ensure all stack allocations happen on every find_day run
to keep stack size consistent between runs with and without flags
1 parent 33c2afa commit 4899c91

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ccronexpr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,20 +618,20 @@ find_next_day(struct tm *calendar, const uint8_t *cron_dom, unsigned int day_of_
618618
// Copy cron_dom to add days determined by L- and W- flags
619619
uint8_t cur_doms[4];
620620
memcpy(cur_doms, cron_dom, 4);
621+
// Copy calendar to move day independently searching for L/W-Days; timezone MUST not be touched
622+
// find_{L,W}_days() will not alter the original tm struct
623+
struct tm searcher;
621624
if (lw_flags) {
622-
// Copy calendar to move day independently searching for L/W-Days; timezone MUST not be touched
623-
// find_{L,W}_days() will not alter the tm struct
624-
struct tm searcher;
625625
memcpy(&searcher, calendar, sizeof searcher);
626626
// Add L days and W days of current month to cur_doms
627627
find_l_days(&searcher, cur_doms, l_dow_flags, l_dom_offset, lw_flags, res_out);
628628
if (*res_out) {
629-
// something went wrong; return 0
629+
// something went wrong; keep res_out value, return 0
630630
return 0;
631631
}
632632
find_w_days(&searcher, cur_doms, w_flags, res_out);
633633
if (*res_out) {
634-
// something went wrong; return 0
634+
// something went wrong; keep res_out value, return 0
635635
return 0;
636636
}
637637
// Get last day of current month: 0th day of next month

ccronexpr_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ void test_expr() {
530530
assert(check_next("0 0 12 1W,15W * ?","2025-05-01_11:00:00", "2025-05-01_12:00:00"));
531531
assert(check_next("0 0 12 1W,15W * ?","2025-05-01_13:01:00", "2025-05-15_12:00:00"));
532532
assert(check_next("0 0 12 1W,15W * ?","2025-05-15_12:01:00", "2025-06-02_12:00:00"));
533+
// check 1st february 2025
534+
assert(check_next("0 0 12 1,15 * ?", "2025-01-31_12:00:00", "2025-02-01_12:00:00"));
535+
assert(check_next("0 0 12 1W,15W * ?", "2025-01-31_12:00:00", "2025-02-03_12:00:00"));
533536
}
534537

535538
void test_parse() {

0 commit comments

Comments
 (0)