From d24c5a0105b14dd20efd6c3c9f1ae0a35ca50c84 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 24 Jan 2017 20:39:45 +1100 Subject: [PATCH] coroutine: Move total initialization outside coroutine The sample coroutine in api-3 initializes a total to 0, then adds up the pseudo-random data it has placed into a stack buffer, to ensure that the compiler won't elide the reading and writing of that buffer. After the coroutine has completed, we verify that total is non-zero so that we'll detect if the coroutine failed to execute entirely. Except that the initialization of total is within the coroutine itself, so it could also be non-zero due to it simply being uninitialized. This moves the initialization outside the coroutine, to make the test a little more robust. Signed-off-by: David Gibson --- ccan/coroutine/test/api-3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ccan/coroutine/test/api-3.c b/ccan/coroutine/test/api-3.c index dcc35312..12912654 100644 --- a/ccan/coroutine/test/api-3.c +++ b/ccan/coroutine/test/api-3.c @@ -27,7 +27,6 @@ static void clobber(void *p) buf[i] = random() & 0xff; } - s->total = 0; for (i = 0; i < sizeof(buf); i++) { s->total += buf[i]; } @@ -48,6 +47,7 @@ static void test_metadata(struct coroutine_stack *stack) if (COROUTINE_AVAILABLE) { struct coroutine_state t; struct state s = { + .total = 0, }; coroutine_init(&t, clobber, &s, stack); -- 2.39.2