Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3931

Non-boolean assignments should not be used as conditions

    XMLWordPrintable

    Details

    • Message:
      Refactor this suspicious code to not use the result of this non-boolean assignment as a condition
    • Highlighting:
      Hide

      The overall non-boolean assignment

      Show
      The overall non-boolean assignment
    • Default Severity:
      Blocker
    • Impact:
      High
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      C++, Cobol, JavaScript, PHP, PL/SQL, Swift
    • Irrelevant for Languages:
      C#, C, Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources
    • CERT:
      EXP19-CPP, EXP19-CPP.
    • MISRA C 2004:
      13.1

      Description

      Using the output of a non-boolean assignment as a condition is highly suspicious. Either it was done accidentally, and the assignment operator = was used in place of the equality operator ==, or it was done with the intent to rely on the automatic conversion of the non-boolean value to a boolean, which could be confusing for maintainers.

      See

      • MISRA C:2004, 13.1 - Assignment operators shall not be used in expressions that yield a Boolean value

        Attachments

          Issue Links

          1.
          JavaScript RSPEC-3932 Language-Specification Active Unassigned
          2.
          C-Family RSPEC-3933 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              freddy.mallet Freddy Mallet (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: