From patchwork Thu Feb 5 08:15:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 44405 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 544A121173 for ; Thu, 5 Feb 2015 08:16:33 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id b6sf4258198lbj.0 for ; Thu, 05 Feb 2015 00:16:32 -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=ahksAYO/HlW57qw7hgxCHs5zTgBTTPSTOQuYAc4hQik=; b=lijpbkpgx9UWncsLM2x0kqp8lr5J3gjfWzc+n1ZlihTocyrnknGTUCmnF9WLWsoTyV zGtXqVH1BrmIzFUxoXtT4wmYipW4djZEpTbZsEaDpuxnnP/Kt4ByeUAuubIKsTaUzPyz /i6AkamSLh8p7MNWmb74YkesY+jJjx/dSqMMtZPQ8nKT55YVCTTTUSGYMjUk8gl7Kgxy vuo9lGwgBQbzw+14nNIAtVOJTtTeuI3Uhr1aZ/nJP9IIRaZBGXaXAZc501XkrP4yh7Jo zUYxkwrFAxZEE8WztiOrQdax6lifHLAoEKF5RhNzdik4XxRcxTFeTezyxzZo6rwwreXl ZL2g== X-Gm-Message-State: ALoCoQmZuPH3mzfuN67grtbf1rEVfZuQD7fPo0NDUnJcofVlPIlHziGOOpl5vLG/vQsjHJTZSmYf X-Received: by 10.112.133.98 with SMTP id pb2mr292812lbb.2.1423124192288; Thu, 05 Feb 2015 00:16:32 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.11 with SMTP id lc11ls133826lac.19.gmail; Thu, 05 Feb 2015 00:16:32 -0800 (PST) X-Received: by 10.112.137.38 with SMTP id qf6mr2015238lbb.59.1423124192072; Thu, 05 Feb 2015 00:16:32 -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 bf5si3287320lab.128.2015.02.05.00.16.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Feb 2015 00:16:32 -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 u14so5680639lbd.2 for ; Thu, 05 Feb 2015 00:16:32 -0800 (PST) X-Received: by 10.152.5.226 with SMTP id v2mr2160317lav.34.1423124191988; Thu, 05 Feb 2015 00:16:31 -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 h5csp991835lbj; Thu, 5 Feb 2015 00:16:31 -0800 (PST) X-Received: by 10.229.70.133 with SMTP id d5mr5947335qcj.2.1423124190573; Thu, 05 Feb 2015 00:16:30 -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 r8si5364990qac.28.2015.02.05.00.16.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 05 Feb 2015 00:16:30 -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 1YJHbv-0003b9-H0; Thu, 05 Feb 2015 08:16:27 +0000 Received: from mail-lb0-f171.google.com ([209.85.217.171]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YJHbi-0003a9-Jq for lng-odp@lists.linaro.org; Thu, 05 Feb 2015 08:16:14 +0000 Received: by mail-lb0-f171.google.com with SMTP id u14so5679363lbd.2 for ; Thu, 05 Feb 2015 00:16:09 -0800 (PST) X-Received: by 10.152.183.196 with SMTP id eo4mr2217173lac.0.1423124168792; Thu, 05 Feb 2015 00:16:08 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id nq7sm807336lbb.49.2015.02.05.00.16.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Feb 2015 00:16:07 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 5 Feb 2015 09:15:57 +0100 Message-Id: <1423124161-18716-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423124161-18716-1-git-send-email-ola.liljedahl@linaro.org> References: <1423124161-18716-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCHv5 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 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