From 534ad99dc5c472b3d3cc04108bd8aea676bb7fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radom=C3=ADr=20Pol=C3=A1ch?= Date: Thu, 7 Sep 2023 20:31:47 +0200 Subject: [PATCH] fix: https://github.com/staticlibs/ccronexpr/issues/32 --- CMakeLists.txt | 2 +- Makefile | 1 + ccronexpr.c | 12 ++++++------ ccronexpr_test.c | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd71993..154f6ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ if (MSVC) target_compile_definitions(ccronexpr PRIVATE _CRT_SECURE_NO_WARNINGS) else () # Strict compilation - target_compile_options(ccronexpr PRIVATE -ansi -Wall -Wextra -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -pedantic-errors) + target_compile_options(ccronexpr PRIVATE -ansi -Wall -Wextra -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -Wno-unused-parameter -pedantic-errors) endif () # Tests diff --git a/Makefile b/Makefile index b64c062..51eb41c 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ ifeq ($(strip $(UNCOMMITTED_CHANGES)),) else VERSION := $(VERSION)-dev-build endif +CFLAGS = -Wextra -std=c89 -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-z,norelro -Wno-unused-parameter -static -DVERSION=\"$(VERSION)\" -DCRON_USE_LOCAL_TIME CFLAGS = -Wextra -std=c89 -s -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-z,norelro -static -DVERSION=\"$(VERSION)\" -DCRON_USE_LOCAL_TIME SOURCES = supertinycron.c ccronexpr.c ccronexpr_test.c OBJECTS = supertinycron.o ccronexpr.o diff --git a/ccronexpr.c b/ccronexpr.c index 11a3aa9..b2e1386 100644 --- a/ccronexpr.c +++ b/ccronexpr.c @@ -562,7 +562,7 @@ static int do_nextprev( int (*do_)(cron_expr* expr, struct tm* calendar, int dot), int (*find_day)(struct tm* calendar, uint8_t* days_of_month, int8_t* day_in_month, int day_of_month, uint8_t* days_of_week, int day_of_week, uint8_t* flags, int* resets, int* res_out), int (*find_offset)(uint8_t* bits, int max, int value, int offset, struct tm* calendar, int field, int nextField, int* lower_orders, int* res_out), - cron_expr* expr, struct tm* calendar, int dot, int offset) { + cron_expr* expr, struct tm* calendar, int dot) { int i; int res = 0; int resets[CRON_CF_ARR_LEN]; @@ -628,7 +628,7 @@ static int do_nextprev( update_month = find(expr->months, CRON_MAX_MONTHS, month, calendar, CRON_CF_MONTH, CRON_CF_YEAR, resets, &res); if (0 != res) goto return_result; if (month != update_month) { - if ((calendar->tm_year - dot)*offset > CRON_MAX_YEARS_DIFF) { + if (abs(calendar->tm_year - dot) > CRON_MAX_YEARS_DIFF) { res = -1; goto return_result; } @@ -651,7 +651,7 @@ static int do_nextprev( } static int do_next(cron_expr* expr, struct tm* calendar, int dot) { - return do_nextprev(find_next, do_next, find_next_day, find_next_offset, expr, calendar, dot, 1); + return do_nextprev(find_next, do_next, find_next_day, find_next_offset, expr, calendar, dot); } static int to_upper(char* str) { @@ -1299,10 +1299,10 @@ static int find_prev_offset(uint8_t* bits, int max, int value, int offset, struc next_value = prev_set_bit(bits, max - 1, value, ¬found); } if (notfound || next_value != value) { - err = set_field(calendar, field, next_value); - if (err) goto return_error; err = reset_all_max(calendar, lower_orders); if (err) goto return_error; + err = set_field(calendar, field, next_value); + if (err) goto return_error; } return next_value; @@ -1335,7 +1335,7 @@ static int find_prev_day(struct tm* calendar, uint8_t* days_of_month, int8_t* da } static int do_prev(cron_expr* expr, struct tm* calendar, int dot) { - return do_nextprev(find_prev, do_prev, find_prev_day, find_prev_offset, expr, calendar, dot, -1); + return do_nextprev(find_prev, do_prev, find_prev_day, find_prev_offset, expr, calendar, dot); } time_t cron_prev(cron_expr* expr, time_t date) { diff --git a/ccronexpr_test.c b/ccronexpr_test.c index 6c10358..7e7405b 100644 --- a/ccronexpr_test.c +++ b/ccronexpr_test.c @@ -486,7 +486,7 @@ void test_expr() { check_fn(cron_next, "0 0 0 ? 4-5 *", "2022-03-31_00:00:00", "2022-04-01_00:00:00", __LINE__); check_fn(cron_next, "* * * 29 2 *", "2021-12-07_12:00:00", "2024-02-29_00:00:00", __LINE__); - /*check_fn(cron_prev, "* * * 29 2 *", "2021-12-07_12:00:00", "2024-02-29_00:00:00", __LINE__);*/ + check_fn(cron_prev, "* * * 29 2 *", "2021-12-07_12:00:00", "2020-02-29_23:59:59", __LINE__); } void test_parse() {