Fix: tests/bp_account.c:154:9: runtime error: variable length array bound evaluates to non-positive value 0 by switching from a variable length to an allocated array.
Unified · Split
| @@ -151,11 +151,21 @@ static int detect_ioctl(void) · 150 unmodified lines | ||
| 151 | 151 | static int detect_share(int wp_cnt, int bp_cnt) |
| 152 | 152 | { |
| 153 | 153 | struct perf_event_attr attr; |
| 154 | − int i, fd[wp_cnt + bp_cnt], ret; | |
| 154 | + int i, *fd = NULL, ret = -1; | |
| 155 | + | |
| 156 | + if (wp_cnt + bp_cnt == 0) | |
| 157 | + return 0; | |
| 158 | + | |
| 159 | + fd = malloc(sizeof(int) * (wp_cnt + bp_cnt)); | |
| 160 | + if (!fd) | |
| 161 | + return -1; | |
| 155 | 162 | |
| 156 | 163 | for (i = 0; i < wp_cnt; i++) { |
| 157 | 164 | fd[i] = wp_event((void *)&the_var, &attr); |
| 158 | − TEST_ASSERT_VAL("failed to create wp\n", fd[i] != -1); | |
| 165 | + if (fd[i] == -1) { | |
| 166 | + pr_err("failed to create wp\n"); | |
| 167 | + goto out; | |
| 168 | + } | |
| 159 | 169 | } |
| 160 | 170 | |
| 161 | 171 | for (; i < (bp_cnt + wp_cnt); i++) { |
| @@ -166,9 +176,11 @@ static int detect_share(int wp_cnt, int bp_cnt) · 4 unmodified lines | ||
| 166 | 176 | |
| 167 | 177 | ret = i != (bp_cnt + wp_cnt); |
| 168 | 178 | |
| 179 | +out: | |
| 169 | 180 | while (i--) |
| 170 | 181 | close(fd[i]); |
| 171 | 182 | |
| 183 | + free(fd); | |
| 172 | 184 | return ret; |
| 173 | 185 | } |
| 174 | 186 | |