Skip to content

Commit 41b8e05

Browse files
ytcoodeNobody
authored andcommitted
selftests/bpf: Fix issues in parse_num_list()
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]>
1 parent 31256d8 commit 41b8e05

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tools/testing/selftests/bpf/testing_helpers.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len)
2020
if (errno)
2121
return -errno;
2222

23-
if (parsing_end)
24-
end = num;
25-
else
23+
if (!parsing_end) {
2624
start = num;
25+
if (*next == '-') {
26+
s = next + 1;
27+
parsing_end = true;
28+
continue;
29+
}
30+
}
2731

28-
if (!parsing_end && *next == '-') {
29-
s = next + 1;
30-
parsing_end = true;
31-
continue;
32-
} else if (*next == ',') {
32+
if (*next == ',') {
3333
parsing_end = false;
3434
s = next + 1;
3535
end = num;
@@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len)
6060
set[i] = true;
6161
}
6262

63-
if (!set)
63+
if (!set || parsing_end)
6464
return -EINVAL;
6565

6666
*num_set = set;

0 commit comments

Comments
 (0)