From 0627b26b747b946c988d2ed4ce466691b1f4e98d Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 20 Dec 2017 10:31:07 +0300 Subject: [PATCH] Fill in allocated memory with values depending on thread id (test_malloc) * tests/test_malloc.c (run_one_test): Define new local variables a, b (with the values depending on arg); replace 'a' and 'b' with a and b, respectively; reformat the code; return NULL instead of arg; remove the comment (the workaround is no longer needed). --- tests/test_malloc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_malloc.c b/tests/test_malloc.c index f799430..a7b36bd 100644 --- a/tests/test_malloc.c +++ b/tests/test_malloc.c @@ -172,6 +172,8 @@ void * run_one_test(void * arg) { int i; char *p = AO_malloc(LARGE_OBJ_SIZE); char *q; + char a = 'a' + ((int)((AO_PTRDIFF_T)arg) * 2) % ('z' - 'a' + 1); + char b = a + 1; if (0 == p) { # ifdef HAVE_MMAP @@ -182,7 +184,7 @@ void * run_one_test(void * arg) { LARGE_OBJ_SIZE); # endif } else { - p[0] = p[LARGE_OBJ_SIZE/2] = p[LARGE_OBJ_SIZE-1] = 'a'; + p[0] = p[LARGE_OBJ_SIZE/2] = p[LARGE_OBJ_SIZE-1] = a; q = AO_malloc(LARGE_OBJ_SIZE); if (q == 0) { @@ -190,15 +192,13 @@ void * run_one_test(void * arg) { /* Normal for more than about 10 threads without mmap? */ exit(2); } - q[0] = q[LARGE_OBJ_SIZE/2] = q[LARGE_OBJ_SIZE-1] = 'b'; - if (p[0] != 'a' || p[LARGE_OBJ_SIZE/2] != 'a' - || p[LARGE_OBJ_SIZE-1] != 'a') { + q[0] = q[LARGE_OBJ_SIZE/2] = q[LARGE_OBJ_SIZE-1] = b; + if (p[0] != a || p[LARGE_OBJ_SIZE/2] != a || p[LARGE_OBJ_SIZE-1] != a) { fprintf(stderr, "First large allocation smashed\n"); abort(); } AO_free(p); - if (q[0] != 'b' || q[LARGE_OBJ_SIZE/2] != 'b' - || q[LARGE_OBJ_SIZE-1] != 'b') { + if (q[0] != b || q[LARGE_OBJ_SIZE/2] != b || q[LARGE_OBJ_SIZE-1] != b) { fprintf(stderr, "Second large allocation smashed\n"); abort(); } @@ -215,7 +215,7 @@ void * run_one_test(void * arg) { } check_list(x, 1, LIST_LENGTH); free_list(x); - return arg; /* use arg to suppress compiler warning */ + return NULL; } #ifndef LOG_MAX_SIZE -- 2.40.0