diff mbox

[PATCHv5,2/6] validation: odp_timer.c: avoid dereferencing ptr after NULL check

Message ID 1423124161-18716-3-git-send-email-ola.liljedahl@linaro.org
State Accepted
Commit 91f09810380341de6ba31faccdbe6ab226a29c43
Headers show

Commit Message

Ola Liljedahl Feb. 5, 2015, 8:15 a.m. UTC
Don't dereference pointer after successful check for NULL as this makes Coverity
complain. (Coverity CID 85397, https://bugs.linaro.org/show_bug.cgi?id=1056)

Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org>
---
(This document/code contribution attached is provided under the terms of
agreement LES-LTM-21309)

 test/validation/odp_timer.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c
index c098b20..3fc9327 100644
--- a/test/validation/odp_timer.c
+++ b/test/validation/odp_timer.c
@@ -69,23 +69,23 @@  static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick)
 	if (ttp == NULL)
 		CU_FAIL("odp_timeout_user_ptr() null user ptr");
 
-	if (ttp->ev2 != ev)
+	if (ttp != NULL && ttp->ev2 != ev)
 		CU_FAIL("odp_timeout_user_ptr() wrong user ptr");
-	if (ttp->tim != tim)
+	if (ttp != NULL && ttp->tim != tim)
 		CU_FAIL("odp_timeout_timer() wrong timer");
 	if (stale) {
 		if (odp_timeout_fresh(tmo))
 			CU_FAIL("Wrong status (fresh) for stale timeout");
 		/* Stale timeout => local timer must have invalid tick */
-		if (ttp->tick != TICK_INVALID)
+		if (ttp != NULL && ttp->tick != TICK_INVALID)
 			CU_FAIL("Stale timeout for active timer");
 	} else {
 		if (!odp_timeout_fresh(tmo))
 			CU_FAIL("Wrong status (stale) for fresh timeout");
 		/* Fresh timeout => local timer must have matching tick */
-		if (ttp->tick != tick) {
+		if (ttp != NULL && ttp->tick != tick) {
 			printf("Wrong tick: expected %"PRIu64" actual %"PRIu64"\n",
-			       ttp->tick, tick);
+				ttp->tick, tick);
 			CU_FAIL("odp_timeout_tick() wrong tick");
 		}
 		/* Check that timeout was delivered 'timely' */
@@ -99,9 +99,11 @@  static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick)
 		}
 	}
 
-	/* Use assert() for correctness check of test program itself */
-	assert(ttp->ev == ODP_EVENT_INVALID);
-	ttp->ev = ev;
+	if (ttp != NULL) {
+		/* Internal error */
+		CU_ASSERT_FATAL(ttp->ev == ODP_EVENT_INVALID);
+		ttp->ev = ev;
+	}
 }
 
 /* @private Worker thread entrypoint which performs timer alloc/set/cancel/free