From fdf9238382a6a7ed14f0676f68adf40e1abda58d Mon Sep 17 00:00:00 2001 From: Sergio Rodriguez Date: Thu, 26 Jan 2017 11:18:32 -0800 Subject: [PATCH] tests: context: Verify for out of bounds array The for loop could exit with a out of bounds (variable j) value for the delayed_threads array, we verify for the variable value before operating on the array This issue was reported by Coverity Coverity-CID: 160078 Change-Id: I6aa1cc325cc363be48cd72b2a58d0a55ec3854bc Signed-off-by: Sergio Rodriguez --- tests/kernel/context/src/context.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/kernel/context/src/context.c b/tests/kernel/context/src/context.c index cace82008f9..04b61b935fc 100644 --- a/tests/kernel/context/src/context.c +++ b/tests/kernel/context/src/context.c @@ -784,9 +784,12 @@ static int test_timeout(void) break; } } - k_thread_cancel(delayed_threads[j]); - ++next_cancellation; - continue; + + if (j < NUM_TIMEOUT_THREADS) { + k_thread_cancel(delayed_threads[j]); + ++next_cancellation; + continue; + } } data = k_fifo_get(&timeout_order_fifo, 2750);