Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -4558,9 +4558,11 @@
sscanf(template, "%[^[\[][%d-%d]%[^\n]", before, &from, &to, after);
}

if (step_size < 1 || abs(from-to) < step_size)
if (step_size < 1)
{
FatalError(ctx, "EXPANDRANGE Step size cannot be less than 1 or greater than the interval");
assert(fp->name != NULL);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you tried to fix the CodeQL issue. Can you change it to

assert(fp != NULL);

and put it in the top of the function?

Log(LOG_LEVEL_ERR, "%s: Step size cannot be less than 1", fp->name);
Comment thread Fixed
return FnFailure();
}

if (from == CF_NOINT || to == CF_NOINT)
Expand Down
43 changes: 43 additions & 0 deletions tests/acceptance/01_vars/02_functions/expand_range.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# data_regextract() test

body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => { default("$(this.promise_filename)") };
}

bundle agent test
{
vars:
"case1" slist => expandrange("case1[1-3]", 1);
"case1s" string => format("%S", "case1");
"case2" slist => expandrange("case2[1-10]", 3);
"case2s" string => format("%S", "case2");
"case3" slist => expandrange("case3[1-1]", 3);
"case3s" string => format("%S", "case3");
"case4" slist => expandrange("case4[1-2]", 3);
"case4s" string => format("%S", "case4");
}

bundle agent check
{
vars:
"actual" string => "
1 $(test.case1s)
2 $(test.case2s)
3 $(test.case3s)
4 $(test.case4s)
";

"expected" string => '
1 { \"case11\", \"case12\", \"case13\" }
2 { \"case21\", \"case24\", \"case27\", \"case210\" }
3 { \"case31\" }
4 { \"case41\" }
';

methods:
"" usebundle => dcs_check_strcmp($(actual), $(expected),
$(this.promise_filename),
"no");
}
Loading