From patchwork Thu Jan 29 15:32:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 43942 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1C46B2410D for ; Thu, 29 Jan 2015 15:33:15 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id l4sf21195675lbv.1 for ; Thu, 29 Jan 2015 07:33:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=RT9vNEnSXlNhhcBW8QITSEtJ5RnGR4C37RUKGBN7xlA=; b=ll83x61p2+C7gzXn8FGybE+6eIL/FuEAcwBr2e//p0mgagZbGg9Bpxi6WqxYC/JePh FULqXTcnzVAsiPZXQn7siBd/ZVsf+fU+ig2BLt8ZP+pNUX3M+3Ozz7zt7zLaAM7E3NW0 bASTyKIlKUvl03untntNrWHBI+Dlo9dkSpQCKw8wsVuL4ry8jw2dz+8gPep0/mShh9Bl xajApttx2rAJQIv3ZadcroH2a+m9wn1EW41PbzgbeoTtbgnv/nP8wRVBmcP6tyJYE3IS 2qL0RXShwQn4vdNo1pHERrmUUuv1SNHJnac99f2ryj94gKSkRkX4ybBuQM1+5Okg09XG KxcQ== X-Gm-Message-State: ALoCoQlgEaUM98I9f3391rPlm8130nPwnEpdVQmG981Lmb1Z/D2HMaO3/4sv/AXPPVyE0rd/Zt3O X-Received: by 10.112.174.36 with SMTP id bp4mr175816lbc.15.1422545592752; Thu, 29 Jan 2015 07:33:12 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.42 with SMTP id x10ls162971lax.96.gmail; Thu, 29 Jan 2015 07:33:12 -0800 (PST) X-Received: by 10.152.5.101 with SMTP id r5mr1477737lar.33.1422545592557; Thu, 29 Jan 2015 07:33:12 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id qc5si3008681lbb.51.2015.01.29.07.33.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Jan 2015 07:33:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id f15so29366596lbj.0 for ; Thu, 29 Jan 2015 07:33:12 -0800 (PST) X-Received: by 10.152.245.44 with SMTP id xl12mr1414536lac.81.1422545592026; Thu, 29 Jan 2015 07:33:12 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1798660lbj; Thu, 29 Jan 2015 07:33:11 -0800 (PST) X-Received: by 10.236.43.239 with SMTP id l75mr812744yhb.28.1422545590686; Thu, 29 Jan 2015 07:33:10 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id l10si10582760qao.23.2015.01.29.07.33.09 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 29 Jan 2015 07:33:10 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YGr5f-00043p-Cv; Thu, 29 Jan 2015 15:33:07 +0000 Received: from mail-lb0-f173.google.com ([209.85.217.173]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YGr5T-00042Y-Gr for lng-odp@lists.linaro.org; Thu, 29 Jan 2015 15:32:55 +0000 Received: by mail-lb0-f173.google.com with SMTP id p9so29408602lbv.4 for ; Thu, 29 Jan 2015 07:32:49 -0800 (PST) X-Received: by 10.152.161.168 with SMTP id xt8mr1478173lab.35.1422545569538; Thu, 29 Jan 2015 07:32:49 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id rv1sm2172650lbb.25.2015.01.29.07.32.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 07:32:48 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 29 Jan 2015 16:32:37 +0100 Message-Id: <1422545560-6466-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422545560-6466-1-git-send-email-ola.liljedahl@linaro.org> References: <1422545560-6466-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCHv4 2/5] validation: odp_timer.c: avoid dereferencing ptr after NULL check X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ola.liljedahl@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 --- (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 --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c index 0238cf4..6aace14 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