From patchwork Tue Feb 3 15:44:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 44250 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 75D9321513 for ; Tue, 3 Feb 2015 15:44:45 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x12sf21327804wgg.0 for ; Tue, 03 Feb 2015 07:44:44 -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=em9D6yQ1gX+3fA3ZQBwjT1jn2F55ZftxJQeHSkUn6xtvZDBV85WkxLYP3vlROv0/mA OmYfzY/CAHLwBOH7DZR9S/Zh6pH9xQ1Qv1yT960k+vI8FC7Z5+1tSgYutRVPky50jIpO iLa2O0zvKPQvln1D75/MYUk1tUskeHTJg5/3CBQB63Zb4STt39DxLcsKDIPQ1EdX6zxA zcAux5ve2JDt936B/DkWJT3gGeItXXZtQzxFkOZ+ZyCMrCk30tZ7nGvT0le6DooZfeZx WQMxwwTQVF8a9DvKt8c9zinYdCoO4JqyPy7onnUYEV7aZg6++2dh84tucwF0OKmfftag ZZqQ== X-Gm-Message-State: ALoCoQnmza/CMaSlqnvywxEiWbgL1NesKFPJEjzrpDWBsXalTBorzkwZ7ykqJKPy0Cl+Sk/bZtyu X-Received: by 10.112.160.3 with SMTP id xg3mr917586lbb.5.1422978284673; Tue, 03 Feb 2015 07:44:44 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.9 with SMTP id p9ls708961lag.86.gmail; Tue, 03 Feb 2015 07:44:44 -0800 (PST) X-Received: by 10.152.9.41 with SMTP id w9mr24798385laa.17.1422978284527; Tue, 03 Feb 2015 07:44:44 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id x10si19527735lal.31.2015.02.03.07.44.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Feb 2015 07:44:44 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id u14so39212270lbd.2 for ; Tue, 03 Feb 2015 07:44:44 -0800 (PST) X-Received: by 10.152.20.169 with SMTP id o9mr25497257lae.50.1422978284361; Tue, 03 Feb 2015 07:44:44 -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 h5csp2018718lbj; Tue, 3 Feb 2015 07:44:43 -0800 (PST) X-Received: by 10.229.37.136 with SMTP id x8mr10580187qcd.30.1422978283067; Tue, 03 Feb 2015 07:44:43 -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 o8si29186556qab.52.2015.02.03.07.44.41 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Feb 2015 07:44:43 -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 1YIfeZ-0004tj-PS; Tue, 03 Feb 2015 15:44:39 +0000 Received: from mail-lb0-f181.google.com ([209.85.217.181]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIfeN-0004sf-Gq for lng-odp@lists.linaro.org; Tue, 03 Feb 2015 15:44:27 +0000 Received: by mail-lb0-f181.google.com with SMTP id u10so39339128lbd.12 for ; Tue, 03 Feb 2015 07:44:22 -0800 (PST) X-Received: by 10.152.4.102 with SMTP id j6mr25154686laj.95.1422978261937; Tue, 03 Feb 2015 07:44:21 -0800 (PST) Received: from localhost.localdomain (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id k2sm325464lah.32.2015.02.03.07.44.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Feb 2015 07:44:20 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 3 Feb 2015 16:44:09 +0100 Message-Id: <1422978253-7721-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422978253-7721-1-git-send-email-ola.liljedahl@linaro.org> References: <1422978253-7721-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCHv4 2/6] 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.171 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