Incorrectly indented statement
Description
This defect occurs when the indentation of a
statement makes it appear as part of an if
, else
or
another block but the arrangement or lack of braces actually keeps the statement outside the
block.
Risk
A developer or reviewer might incorrectly associate the statement with a block based on its indentation, leading to an incorrect assumption about the program logic.
For instance, in this example:
if(credentialsOK()) login=1; setCookies();
setCookies();
is not part of the if
block, but
the indentation suggests otherwise.Fix
If you want a statement to be part of a block, make sure that the statement is within the braces associated with the block. To identify the extent of a block, on the Source pane, click the opening brace.
If an if
, else
or while
statement has no braces following the condition, only the next line on an execution path up
to a semicolon is considered part of the if
, else
or
while
block. If you want subsequent lines to be included in the block,
wrap the lines in braces.
For instance, in the preceding example, to include both statements in the
if
block,
use:
if(credentialsOK()) { login=1; setCookies(); }
Examples
Result Information
Group: Good practice |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
INCORRECT_INDENTATION |
Impact: Low |
Version History
Introduced in R2020a
See Also
Find defects
(-checkers)
| Semicolon on same line as if, for or
while statement
| Line
with more than one statement
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)