Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Do not use the same variable name in two scopes where one scope is contained in another. For example,

  • No other variable should share the name of a global variable if the other variable is in a subscope of the global variable.
  • A block should not declare a variable with the same name as a variable declared in any block that contains it.

...

By using different variable names globally and locally, the compiler forces the developer to be more precise and descriptive with variable names.

Exceptions

DCL01:-EX1: A function argument in a function declaration may clash with a variable in a containing scope, provided that when the function is defined, the argument has a name that clashes with no variables in any containing scopes.

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

DCL01-C

low

unlikely

medium

P2

L3

Automated Detection

The LDRA tool suite Version 7.6.0 can detect violations of this recommendation.

Splint Version 3.1.1 can detect violations of this recommendation.

Compass/ROSE can detect violations of this recommendation.

...

Tool

Version

Checker

Description

Section

LDRA tool suite

Include Page
c:LDRA_V
c:LDRA_V

 

 

Section

Splint

Include Page
c:Splint_V
c:Splint_V

 

 

Section

Compass/ROSE

 

 

 

Section

Klocwork

Include Page
c:Klocwork_V
c:Klocwork_V
Section

IF_MULTI_DECL

...

IF_MULTI_DEF

...

IF_MULTI_KIND

...

 

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Other Languages

This rule appears in the C++ Secure Coding Standard as : DCL01-CPP. Do not reuse variable names in subscopes.

This rule appears in the Java Secure Coding Standard as : SCP02-J. Do not reuse names.

Bibliography

Wiki Markup
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 5.2.4.1, "Translation limits"
\[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 5.2

...