<dd id="sga4y"><optgroup id="sga4y"></optgroup></dd>
<nav id="sga4y"><code id="sga4y"></code></nav>
  • <optgroup id="sga4y"></optgroup>

    Dead Code: Expression is Always true

    ABSTRACT

    此表達式(或部分表達式)的計算結果始終為 true。

    EXPLANATION

    此表達式(或部分表達式)的計算結果始終為 true;程序可以按一種更為簡單的方式重寫。而其附近代碼的出現可能是出于調試目的,或者可能沒有與程序中的其他代碼一同進行維護。該表達式還可能為我們指出方法中的錯誤所在。

    例 1:以下方法將變量 secondCall 初始化為 true 后,將不會再對該變量進行設置。(變量 firstCall 被錯誤地使用了兩次。)這將會造成表達式 firstCall || secondCall 將總被評估為 true,進而總會調用 setUpForCall()


    public void setUpCalls() {
    boolean firstCall = true;
    boolean secondCall = true;

    if (fCall < 0) {
    cancelFCall();
    firstCall = false;
    }
    if (sCall < 0) {
    cancelSCall();
    firstCall = false;
    }

    if (firstCall || secondCall) {
    setUpForCall();
    }
    }


    例 2:下列方法嘗試檢查變量 firstCallsecondCall。(變量 firstCall 被錯誤地設為 true,而沒有對其進行檢查。)其結果是,表達式 firstCall = true && secondCall == true 的第一部分的計算結果始終為 true。


    public void setUpCalls() {
    boolean firstCall = false;
    boolean secondCall = false;

    if (fCall > 0) {
    setUpFCall();
    firstCall = true;
    }
    if (sCall > 0) {
    setUpSCall();
    secondCall = true;
    }

    if (firstCall = true && secondCall == true) {
    setUpDualCall();
    }
    }

    REFERENCES

    [1] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3050 CAT II

    [2] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3050 CAT II

    [3] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 571


    Copyright 2013 Fortify Software - All rights reserved.
    (Generated from version 2013.1.1.0008 of the Fortify Secure Coding Rulepacks)
    desc.structural.java.dead_code_expression_is_always_true

    97av