Skip to content

Commit

Permalink
fix: concat regular fields mixed with 'W' fields properly
Browse files Browse the repository at this point in the history
Add commas when needed. Also use strcpy and a tracking pointer to make copying more efficient
  • Loading branch information
Kniggebrot committed Oct 22, 2024
1 parent f01bb90 commit ad5be5d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ccronexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,7 @@ static char* w_check(char* field, cron_expr* target, const char** error)
goto return_error;
}
memset(newField, 0, sizeof(char) * strlen(field));
char *tracking = newField;
// Ensure only 1 day is specified, and W day is not the last in a range or list or iterator of days
if ( has_char(field, '/') || has_char(field, '-')) {
*error = "W not allowed in iterators or ranges in 'day of month' field";
Expand Down Expand Up @@ -1563,7 +1564,14 @@ static char* w_check(char* field, cron_expr* target, const char** error)
cron_setBit(target->w_flags, w_day);
}
} else {
strcat(newField, splitField[i]);
if (tracking != newField) {
// A field was already added. Add a comma first
strncpy(tracking, ",", 2); // ensure string ends in '\0', tracking will be set to it
tracking += 1;
}
size_t field_len = strnlen(splitField[i], CRON_MAX_STR_LEN_TO_SPLIT);
strncpy(tracking, splitField[i], field_len);
tracking += field_len;
}
}
free_splitted(splitField, len_out);
Expand Down

0 comments on commit ad5be5d

Please sign in to comment.