From patchwork Thu Jan 29 11:01:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 43920 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2634124119 for ; Thu, 29 Jan 2015 11:01:44 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id u10sf18311764lbd.3 for ; Thu, 29 Jan 2015 03:01:43 -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=Myra4rKguRM4zwA0f92HLnRu58Q732IOa97TE91+hlw=; b=R0kHZfdpCzeOoJsSG3U2YN5A5b7RaZetWcLyRqlsIakpp8F1eRU2jVU9/og5AaaaXh 7zvVBotdwZjcCr3rmxLlv+bGGIXU2aHA27UYCSi627w6NITCXYIfkt9JqIfEUCfk9/1r IHi0x9l5Br13fUAm2wHcNdxGAkSmwej085ID3SyPdKyklPz7T5LifnTaRQE2pNoe4qrm qeMMLjBpVKhs0Tp7vjW8LNT6epLa/Toe2ZygFmn+zMZ0DMcjKMGDdfgOC4p00B3yRXro nyWzNhm7b8ExjhL2NnCkAstHPgS/H8d/pTgpHHotdhc5eX53dCx7Mi6vfq1kl3Q9SSKL yTcQ== X-Gm-Message-State: ALoCoQmTMod1AwyBUXpcg2//ruu1qVM0YQnVgbPFOXXCd3xhvAR0Z2WrF/7CCnTXA+c+0uMBVaiK X-Received: by 10.112.137.70 with SMTP id qg6mr1656481lbb.14.1422529303072; Thu, 29 Jan 2015 03:01:43 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.42 with SMTP id n10ls273339laj.95.gmail; Thu, 29 Jan 2015 03:01:42 -0800 (PST) X-Received: by 10.152.23.73 with SMTP id k9mr71264laf.54.1422529302923; Thu, 29 Jan 2015 03:01:42 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id oi2si6994747lbb.125.2015.01.29.03.01.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Jan 2015 03:01:42 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id l4so26686260lbv.13 for ; Thu, 29 Jan 2015 03:01:42 -0800 (PST) X-Received: by 10.152.116.43 with SMTP id jt11mr13579888lab.69.1422529302822; Thu, 29 Jan 2015 03:01:42 -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 h5csp1724083lbj; Thu, 29 Jan 2015 03:01:42 -0800 (PST) X-Received: by 10.140.100.226 with SMTP id s89mr10316qge.96.1422529301388; Thu, 29 Jan 2015 03:01:41 -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 s3si7539097qak.46.2015.01.29.03.01.39 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 29 Jan 2015 03:01:41 -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 1YGmqw-0007tb-4C; Thu, 29 Jan 2015 11:01:38 +0000 Received: from mail-lb0-f180.google.com ([209.85.217.180]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YGmqi-0007sl-2y for lng-odp@lists.linaro.org; Thu, 29 Jan 2015 11:01:24 +0000 Received: by mail-lb0-f180.google.com with SMTP id b6so26663457lbj.11 for ; Thu, 29 Jan 2015 03:01:18 -0800 (PST) X-Received: by 10.112.161.34 with SMTP id xp2mr13362736lbb.73.1422529278152; Thu, 29 Jan 2015 03:01:18 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id s7sm2045761las.17.2015.01.29.03.01.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 03:01:17 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 29 Jan 2015 12:01:10 +0100 Message-Id: <1422529273-31282-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422529273-31282-1-git-send-email-ola.liljedahl@linaro.org> References: <1422529273-31282-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCHv3 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.182 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 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c index 0238cf4..bc4fdf4 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) { - printf("Wrong tick: expected %"PRIu64" actual %"PRIu64"\n", - ttp->tick, tick); + if (ttp != NULL && ttp->tick != tick) { + LOG_DBG("Wrong tick: expected %"PRIu64" actual %"PRIu64"\n", + 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