JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C#


CSHARP.STRUCT.RC : Redundant Condition (C#)

要旨

A test is always true or always false and can thus be removed.

This checker looks for tests that are useless since, for instance, their outcome drives control to the same execution path, regardless of the test itself. This happens for instance when the empty statement is used after a conditional because the programmer put a semicolon after the conditional. This checker also looks for tests that always have the same outcome (always true or always false).

プロパティ

クラス名 Redundant Condition (C#)
日本語クラス名 Redundant Condition (C#)
クラス分類 信頼性 (reliability)
ニーモニック CSHARP.STRUCT.RC
カテゴリー
CWE CWE:570 Expression is Always False
  CWE:571 Expression is Always True
対応言語 C# で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Redundant Condition (C#)"

using System;

namespace DocumentationExamples
{

    public class UselessTest
    {
        public static void Main(string[] args)
        {
            if (args.Length < 2) ;  // Empty Branch Statement (C#) warning issued here 
            Environment.Exit(-1);
            Go(DateTime.Now.Millisecond % 4 == 0, DateTime.Now.Millisecond % 3 == 0);
            Test(17);
            object o = new object();
            if (o != new object())  // Redundant Condition (C#) warning issued here 
                Console.WriteLine("distinct");
        }
        public static void Go(bool b1, bool b2)
        {
            if (b1 = true)          // Redundant Condition (C#) warning issued here 
                Console.WriteLine("yes");
        }
        private static void Test(int i)
        {
            if (i == 17)            // Redundant Condition (C#) warning issued here 
                Console.WriteLine("17");
        }
    }
}

解決法

Remove the check or complete a conditional with actual then or else branch, instead of an empty statement. Verify if the useless test is the sign of a more significant algorithmic problem.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.