diff --git a/.travis.yml b/.travis.yml index f5843a5..97182b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,12 @@ script: - $CC -DCRON_USE_LOCAL_TIME ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c89 -DCRON_TEST_MALLOC -o a.out && TZ="America/Toronto" ./a.out - $CXX -DCRON_USE_LOCAL_TIME ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -o a.out && TZ="America/Toronto" ./a.out - $CXX -DCRON_USE_LOCAL_TIME ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -DCRON_COMPILE_AS_CXX -o a.out && TZ="America/Toronto" ./a.out + - $CC ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c89 -DCRON_TEST_MALLOC -o a.out && ./a.out + - $CXX ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -o a.out && ./a.out + - $CXX ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -DCRON_COMPILE_AS_CXX -o a.out && ./a.out + - $CC -DCRON_USE_LOCAL_TIME ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c89 -DCRON_TEST_MALLOC -o a.out && TZ="America/Toronto" ./a.out + - $CXX -DCRON_USE_LOCAL_TIME ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -o a.out && TZ="America/Toronto" ./a.out + - $CXX -DCRON_USE_LOCAL_TIME ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -DCRON_COMPILE_AS_CXX -o a.out && TZ="America/Toronto" ./a.out notifications: email: diff --git a/README.md b/README.md index 3418f1c..102f937 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,17 @@ Compilation and tests run examples cl ccronexpr.c ccronexpr_test.c /W4 /D_CRT_SECURE_NO_WARNINGS && ccronexpr.exe + + gcc ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c89 -DCRON_TEST_MALLOC -o a.out && ./a.out + g++ ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -o a.out && ./a.out + g++ ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -DCRON_COMPILE_AS_CXX -o a.out && ./a.out + + clang ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c89 -DCRON_TEST_MALLOC -o a.out && ./a.out + clang++ ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -o a.out && ./a.out + clang++ ccronexpr.c supertinycron.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -DCRON_COMPILE_AS_CXX -o a.out && ./a.out + + cl ccronexpr.c supertinycron.c /W4 /D_CRT_SECURE_NO_WARNINGS && supertinycron.exe + Examples of supported expressions --------------------------------- diff --git a/ccronexpr.c b/ccronexpr.c index 09abcbf..f42527e 100644 --- a/ccronexpr.c +++ b/ccronexpr.c @@ -1027,6 +1027,7 @@ static void set_days_of_week(char* field, uint8_t* days_of_week, int8_t* day_in_ cron_del_bit(days_of_week, 7); } return_error: + return; } static int set_days_of_month(char* field, uint8_t* days_of_month, uint8_t* days_of_week, int8_t* day_in_month, uint8_t* flags, const char** error) { @@ -1169,7 +1170,7 @@ void cron_parse_expr(const char* expression, cron_expr* target, const char** err if (*error) goto return_res; } if (len < 7) { - set_years("*", target->years, error); + set_years((char *)"*", target->years, error); } else { set_years(fields[pos], target->years, error); } diff --git a/supertinycron.c b/supertinycron.c index d7494c2..10dd2b5 100644 --- a/supertinycron.c +++ b/supertinycron.c @@ -13,6 +13,25 @@ #define VERSION "dev-build" #endif +#ifdef CRON_TEST_MALLOC +static int cronAllocations = 0; +static int cronTotalAllocations = 0; +static int maxAlloc = 0; +void* cron_malloc(size_t n) { + cronAllocations++; + cronTotalAllocations++; + if (cronAllocations > maxAlloc) { + maxAlloc = cronAllocations; + } + return malloc(n); +} + +void cron_free(void* p) { + cronAllocations--; + free(p); +} +#endif + typedef struct { char* shell; char* cmd; @@ -103,13 +122,13 @@ int cron_system(const char *shell, const char *command) { } TinyCronJob optsFromEnv() { - TinyCronJob opts = {0}; + TinyCronJob opts; if (getenv("TINYCRON_VERBOSE") != NULL) { opts.verbose = 1; } opts.shell = getenv("SHELL"); if (!opts.shell) { - opts.shell = "/bin/sh"; + opts.shell = (char *)"/bin/sh"; } return opts; } @@ -224,7 +243,7 @@ int main(int argc, char *argv[]) { line_len += argc - 3; line_len += 1; - char *line = malloc(line_len); + char *line = (char *)malloc(line_len); if (!line) { perror("malloc"); return EXIT_FAILURE;