diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-02-09 00:16:47 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-02-09 00:16:47 +0300 |
commit | dfc5459a6904b65f8acfa914e863cc7d6f13be16 (patch) | |
tree | 397cc73b639f2af9f0299bb659cf93a9ed120123 | |
parent | 2902ec7875314632105501f5fc95765dd7a69fd5 (diff) | |
download | libatomic_ops-dfc5459a6904b65f8acfa914e863cc7d6f13be16.tar.gz |
Allocate marks[] dynamically and report all found errors in test_stack
* tests/test_stack.c (marks): Remove static variable.
* tests/test_stack.c (check_list): Declare err_cnt and marks local
variables; allocate marks with calloc() and free it at the end of
function; increment err_cnt instead of abort (after fprintf(stderr));
call abort() at the end of function if err_cnt is non-zero.
-rw-r--r-- | tests/test_stack.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/tests/test_stack.c b/tests/test_stack.c index 160b0dc..76c7271 100644 --- a/tests/test_stack.c +++ b/tests/test_stack.c @@ -112,39 +112,45 @@ void print_list(void) } #endif /* VERBOSE_STACK */ -static char marks[MAX_NTHREADS * (MAX_NTHREADS + 1) / 2 + 1]; - void check_list(int n) { list_element *p; int i; + int err_cnt = 0; + char *marks = (char*)calloc(n + 1, 1); - for (i = 1; i <= n; ++i) marks[i] = 0; + if (0 == marks) + { + fprintf(stderr, "Out of memory (marks)\n"); + exit(2); + } for (p = (list_element *)AO_REAL_HEAD_PTR(the_list); - p != 0; - p = (list_element *)AO_REAL_NEXT_PTR(p -> next)) + p != 0; p = (list_element *)AO_REAL_NEXT_PTR(p -> next)) { i = p -> data; if (i > n || i <= 0) { fprintf(stderr, "Found erroneous list element %d\n", i); - abort(); + err_cnt++; } - if (marks[i] != 0) + else if (marks[i] != 0) { fprintf(stderr, "Found duplicate list element %d\n", i); - abort(); + err_cnt++; } - marks[i] = 1; + else marks[i] = 1; } for (i = 1; i <= n; ++i) if (marks[i] != 1) { fprintf(stderr, "Missing list element %d\n", i); - abort(); + err_cnt++; } + + free(marks); + if (err_cnt > 0) abort(); } volatile AO_t ops_performed = 0; |