Skip to content

Commit

Permalink
selftests/bpf: Fix issues in parse_num_list()
Browse files Browse the repository at this point in the history
There are some issues in parse_num_list():

1. The end variable is assigned twice when parsing_end is true.
2. The function does not check that parsing_end should finally be false.

Clean up parse_num_list() and fix these issues.

Signed-off-by: Yuntao Wang <[email protected]>
  • Loading branch information
ytcoode authored and Nobody committed Apr 4, 2022
1 parent 50fbdbf commit 11d4ec7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tools/testing/selftests/bpf/testing_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len)
if (errno)
return -errno;

if (parsing_end)
end = num;
else
if (!parsing_end) {
start = num;
if (*next == '-') {
s = next + 1;
parsing_end = true;
continue;
}
}

if (!parsing_end && *next == '-') {
s = next + 1;
parsing_end = true;
continue;
} else if (*next == ',') {
if (*next == ',') {
parsing_end = false;
s = next + 1;
end = num;
Expand Down Expand Up @@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len)
set[i] = true;
}

if (!set)
if (!set || parsing_end)
return -EINVAL;

*num_set = set;
Expand Down

0 comments on commit 11d4ec7

Please sign in to comment.