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

"goto" statements should not be used to jump into blocks

    Details

    • Message:
      Restructure this code so so that it doesn't jump into a code block
    • Default Severity:
      Blocker
    • Impact:
      High
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      GotoLabelInNestedBlock
    • Targeted languages:
      ABAP, C#, Cobol, PL/I, PL/SQL, RPG, VB6
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1h
    • PC-Lint:
      9041

      Description

      Use of goto can lead to programs that are extremely difficult to comprehend and analyse, and possibly to unspecified behavior.

      Unfortunately, removing goto from some code can lead to a rewritten version that is even more difficult to understand than the original. Therefore, limited use of goto is sometimes advised.

      However, the use of goto to jump into or out of a sub-block of code, such as into the body of a for loop is never acceptable, because it is extremely difficult to understand and will likely yield results other than what is intended.

        Attachments

          Issue Links

          1.
          C-Family RSPEC-1910 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ann.campbell.2 Ann Campbell
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: