From dfc5459a6904b65f8acfa914e863cc7d6f13be16 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 9 Feb 2022 00:16:47 +0300 Subject: 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. --- tests/test_stack.c | 26 ++++++++++++++++---------- 1 file 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; -- cgit v1.2.1