From patchwork Fri Jan 16 17:05: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: 43259 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 62B70240BA for ; Fri, 16 Jan 2015 17:06:46 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf11981007eek.1 for ; Fri, 16 Jan 2015 09:06:45 -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=QuwhAxraRLxnwtRFrowzoDxnLzKIjrtZt5xaawZwUAM=; b=ZbxJb1dYmNsx+16J5mrobSaG3UzREjWAWafuWa6SGp4+mOoCTUl5Mm53Z0mwhiICWg SjYXz/WhHVeENA/hosRv75WaelCp4IwrcNUrEUOAuEzcBbP+eQVcwGdkkSHOwUw9YtnD dzM6vD6N8umxgGV3DqvbNp3HsWRZz7u5NUAew7rljKRbapdGs+ojs0L9Ga6zU0K523i0 JJ4HYLzFu5+g9ebgIYQ+pwxPigSbgLhxGAUcpHdcvd4kyW6kM2HbyZoanMU7ZS9aU6V4 IHIO8NkOm/oW2Z0e+mh7JszhJviQeORb7fqvSst+HRy6NAaRGERTLSibMaVFo7ohEFRR OU+g== X-Gm-Message-State: ALoCoQkeD6Vbis9Aap73mgmCP+QxvLB9v8pKCx0xFwSHjofKRDbyRMB0IqNYQVTQMJ7/Q+kW/Krk X-Received: by 10.180.74.132 with SMTP id t4mr583300wiv.3.1421428005606; Fri, 16 Jan 2015 09:06:45 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.18.134 with SMTP id w6ls373520lad.63.gmail; Fri, 16 Jan 2015 09:06:45 -0800 (PST) X-Received: by 10.152.5.132 with SMTP id s4mr10796175las.39.1421428005442; Fri, 16 Jan 2015 09:06:45 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id wn3si3564755lbb.25.2015.01.16.09.06.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Jan 2015 09:06:45 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id u14so10013450lbd.12 for ; Fri, 16 Jan 2015 09:06:45 -0800 (PST) X-Received: by 10.152.23.38 with SMTP id j6mr16825657laf.81.1421428005356; Fri, 16 Jan 2015 09:06:45 -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.9.200 with SMTP id c8csp373768lbb; Fri, 16 Jan 2015 09:06:44 -0800 (PST) X-Received: by 10.229.35.74 with SMTP id o10mr26878034qcd.26.1421428002922; Fri, 16 Jan 2015 09:06:42 -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 w48si6698615qgw.36.2015.01.16.09.06.34 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 16 Jan 2015 09:06:42 -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 1YCALw-0000w3-RR; Fri, 16 Jan 2015 17:06:32 +0000 Received: from mail-la0-f51.google.com ([209.85.215.51]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YCALd-0000su-K4 for lng-odp@lists.linaro.org; Fri, 16 Jan 2015 17:06:13 +0000 Received: by mail-la0-f51.google.com with SMTP id ms9so19982757lab.10 for ; Fri, 16 Jan 2015 09:06:07 -0800 (PST) X-Received: by 10.112.156.169 with SMTP id wf9mr16724156lbb.85.1421427967655; Fri, 16 Jan 2015 09:06:07 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id 1sm1578217lay.40.2015.01.16.09.06.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Jan 2015 09:06:06 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Fri, 16 Jan 2015 18:05:57 +0100 Message-Id: <1421427959-11751-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1421427959-11751-1-git-send-email-ola.liljedahl@linaro.org> References: <1421427959-11751-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCHv2 2/4] test: 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.181 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 Reviewed-by: Mike Holmes --- (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 dca01ce..5ba1b84 100644 --- a/test/validation/odp_timer.c +++ b/test/validation/odp_timer.c @@ -69,23 +69,23 @@ static void handle_tmo(odp_buffer_t buf, bool stale, uint64_t prev_tick) if (ttp == NULL) CU_FAIL("odp_timeout_user_ptr() null user ptr"); - if (ttp->buf2 != buf) + if (ttp != NULL && ttp->buf2 != buf) 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_buffer_t buf, bool stale, uint64_t prev_tick) } } - /* Use assert() for correctness check of test program itself */ - assert(ttp->buf == ODP_BUFFER_INVALID); - ttp->buf = buf; + if (ttp != NULL) { + /* Internal error */ + CU_ASSERT_FATAL(ttp->buf == ODP_BUFFER_INVALID); + ttp->buf = buf; + } } /* @private Worker thread entrypoint which performs timer alloc/set/cancel/free