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 and C++
Binaries


LANG.STRUCT.RC : Redundant Condition

Summary

Some condition is either always or never satisfied.

This includes conditions that are introduced by normalization rather than explicit in the code. Warnings for these cases also indicate a degree of redundancy in the analyzed code: see below for some examples.

Properties

Class Name Redundant Condition
Significance redundancy
Mnemonic LANG.STRUCT.RC
Categories
MisraC2025 MisraC2025:14.3 Controlling expressions shall not be invariant
MisraC2023 MisraC2023:14.3 Controlling expressions shall not be invariant
Misra2012 Misra2012:14.3 Controlling expressions shall not be invariant
Misra2004 Misra2004:13.7 Boolean operations whose results are invariant shall not be permitted
MisraC++2023 MisraC++2023:0.0.1 A function shall not contain unreachable statements
  MisraC++2023:0.0.2 Controlling expressions should not be invariant
  MisraC++2023:15.8.1 User-provided copy assignment and move assignment operators shall handle self-assignment
CWE CWE:482 Comparing instead of Assigning
  CWE:570 Expression is Always False
  CWE:571 Expression is Always True
  CWE:1164 Irrelevant Code
CERT-C CERT-C:ERR30-C Take care when reading errno
  CERT-C:MSC07-C Detect and remove dead code
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
CERT-CPP CERT-CPP:OOP54-CPP Gracefully handle self-copy assignment
JSF++ JSF++:81 The assignment operator shall handle self-assignment correctly.
  JSF++:187 All non-null statements shall potentially have a side-effect.
OWASP-2017 OWASP-2017:A3 Sensitive data exposure
OWASP-2021 OWASP-2021:A2 Cryptographic failures
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Redundant Condition"

Example

int lang_struct_rc_1(int i){
    if (i > 0){                                // ok: i>0 can be either true or false
        if (i+1 > 1){           // 'Redundant Condition' warning issued here: 
                                //  if execution reaches this point, i+1>0 is true
      return i;
    }
  }
  return 0;
}

enum color { BLUE, RED, YELLOW };

bool process_bools(bool x, bool y){
  return x && y;
}

bool lang_struct_rc_2(bool doNegate, bool andArg){
    color colA = BLUE;
    color colB = RED;
    if (doNegate){                             // ok: doNegate can be either true or false
        return (bool)colA;              // 'Redundant Condition' warning issued here: 
                                        //     return (bool)colA; 
                                        // is normalized to the form
                                        //     if (colA != 0)
                                        //         TMP=true;
                                        //     else
                                        //         TMP=false;
                                        //     return TMP;
                                        // and (colA != 0) is always true
                                        // 
                                        // While the IF statement cited in the resulting warning report is not explicitly present
                                        // in the code, the warning does signal the presence of redundancy:
                                        //     (bool)colA
                                        // is functionally equivalent to 
                                        //     false
                                        // so neither the cast operation nor the colA variable is actually required.
    }
    return process_bools(colB, andArg); // 'Redundant Condition' warning issued here: 
                                        // negate(colB) coerces colB to bool, and this coercion is similarly
                                        // normalized to an IF expression whose condition is (colB != 0)
                                        // 
                                        // While the IF statement cited in the resulting warning report is not explicitly present
                                        // in the code, the warning does signal the presence of redundancy:
                                        //     process_bools(colB, andArg)
                                        // is functionally equivalent to 
                                        //     process_bools(true, andArg)
                                        // so the colB variable isn't required either.
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

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