From patchwork Fri May 14 12:15:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 438900 Delivered-To: patch@linaro.org Received: by 2002:a02:b78d:0:0:0:0:0 with SMTP id f13csp291630jam; Fri, 14 May 2021 05:24:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD6v3kt5eb2I+N5cgBZrkG3sgcTTaVq/glgX9obuMKK2eRRNIGJKjIxFeNpJW/ry9AvrMJ X-Received: by 2002:ab0:6898:: with SMTP id t24mr35125291uar.120.1620995053614; Fri, 14 May 2021 05:24:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620995053; cv=none; d=google.com; s=arc-20160816; b=gXHQeEGYpnoyYNjIP5YdJBJuiSoYwRFCNrw/6IVg/XVzWQ7EKr3yMpiCfoDSvN/NWI UKRT8TEjhlDkIGEBwKX5RU39AFNi1Oy0X7BmPdvrIDXqgX7IdLRo5pG/WD9S8GGv+aZB 9VgxG1knIhGfaSg9AZFTZkJFOkHxBhe5d+lRlDHn3s6tlzMrMgtU1goclQCRe/BgdhXX UOhJIcu50y7VvGZKXNILdQZzEvFzOFhVOyQ4ZAnE3bgEFsfMj+n2EBzJJOw6tml3yTP9 jGfFwVWoxp1HsQRtxnJXe1a7CWU0Gla6vVsGeXhiv7g+cVb4TDchwvBg0rfoIUW/vW4Q SsRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=14tSB4tTUTQTk3xCoqSM5N90C8CnpaBHwi7JKiwNwTo=; b=HWDYOpr/YwpnYKpR0XTe4PYap0S0VAL5/vZpPtEgaIc7uFuR4f6XvCjGItoZiG00wa UoWr8CQV22gqs/0fUwV2fERHhkLI1LpvXgy45/inC7jvosbS9KVY/6xDusOnqGCBkFZQ JFZQ16sjZGzeMrJpYM1sCxg8KujiBMk1TJDP+wUMmYXtwrrTtZ5UxRQbaGfBxn13qCPb yLPafREITXMxqptoqUDmfX1EHXE8qs8wXkrq9XsSnIMhPlyOBP1NkENnvoIKxViRtUHD CE25PM6P44ZHrqgO5RDwEOreJqXj5Np95VAFLws7BMR9GG+Dyyct8Sgw1UionSR9JCBL z0EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b="RT/HhJRY"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x7si4198476uar.173.2021.05.14.05.24.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 May 2021 05:24:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b="RT/HhJRY"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:54860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhWrV-0003hw-0l for patch@linaro.org; Fri, 14 May 2021 08:24:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhWjj-00015G-1p for qemu-devel@nongnu.org; Fri, 14 May 2021 08:16:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhWje-0005BO-UA for qemu-devel@nongnu.org; Fri, 14 May 2021 08:16:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620994564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=14tSB4tTUTQTk3xCoqSM5N90C8CnpaBHwi7JKiwNwTo=; b=RT/HhJRY0hUT7Qy/XIsJwyL7NNYOsgAMBXB8YEs+SFHuaMZ1/Ou44CVAyRO/cQUNBAno85 +4cXJd72MJzp/h9SrZljKpxHK5XO+9Ou4obItUFBlbR073PpvlwiSfK/mGxSu7TfloxwfM /7CdKJGGiaiCIe+Jgy9Hcr2hM5xDIUY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-mJ0Uph67PiCFJpAJcAE9uw-1; Fri, 14 May 2021 08:16:02 -0400 X-MC-Unique: mJ0Uph67PiCFJpAJcAE9uw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 599C4107ACC7; Fri, 14 May 2021 12:16:01 +0000 (UTC) Received: from thuth.com (ovpn-112-191.ams2.redhat.com [10.36.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 176EF60CCF; Fri, 14 May 2021 12:15:59 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 10/20] tests/qtest/npcm7xx_pwm-test.c: Avoid g_assert_true() for non-test assertions Date: Fri, 14 May 2021 14:15:08 +0200 Message-Id: <20210514121518.832729-11-thuth@redhat.com> In-Reply-To: <20210514121518.832729-1-thuth@redhat.com> References: <20210514121518.832729-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hao Wu , =?utf-8?q?Alex_Benn=C3=A9e?= , Havard Skinnemoen Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell In the glib API, the distinction between g_assert() and g_assert_true() is that the former is for "bug, terminate the application" and the latter is for "test check, on failure either terminate or just mark the testcase as failed". For QEMU, g_assert() is always fatal, so code can assume that if the assertion fails execution does not proceed, but this is not true of g_assert_true(). In npcm7xx_pwm-test, the pwm_index() and pwm_module_index() functions include some assertions that are just guarding against possible bugs in the test code that might lead us to out-of-bounds array accesses. These should use g_assert() because they aren't part of what the test is testing and the code does not correctly handle the case where the condition was false. This fixes some Coverity issues where Coverity knows that g_assert_true() can continue when the condition is false and complains about the possible array overrun at various callsites. Fixes: Coverity CID 1442340, 1442341, 1442343, 1442344, 1442345, 1442346 Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth Reviewed-by: Hao Wu Reviewed-by: Havard Skinnemoen Message-Id: <20210505135516.21097-1-peter.maydell@linaro.org> Signed-off-by: Thomas Huth --- tests/qtest/npcm7xx_pwm-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.27.0 diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c index bd15a1c294..a54fd70d27 100644 --- a/tests/qtest/npcm7xx_pwm-test.c +++ b/tests/qtest/npcm7xx_pwm-test.c @@ -201,7 +201,7 @@ static int pwm_module_index(const PWMModule *module) { ptrdiff_t diff = module - pwm_module_list; - g_assert_true(diff >= 0 && diff < ARRAY_SIZE(pwm_module_list)); + g_assert(diff >= 0 && diff < ARRAY_SIZE(pwm_module_list)); return diff; } @@ -211,7 +211,7 @@ static int pwm_index(const PWM *pwm) { ptrdiff_t diff = pwm - pwm_list; - g_assert_true(diff >= 0 && diff < ARRAY_SIZE(pwm_list)); + g_assert(diff >= 0 && diff < ARRAY_SIZE(pwm_list)); return diff; }