Versions Compared

Key

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

...

Footnote 103 in subclause 6.5.3.4 of the C Standard [ISO/IEC 9899:2011] explainsapplies to all array parameters:

When applied to a parameter declared to have array or function type, the sizeof operator yields the size of the adjusted (pointer) type.

This applies to all array parameters.

Compliant Solution

In this compliant solution, the size of the array is determined inside the block in which it is declared and passed as an argument to the function:

...

In this noncompliant code example, the sizeof a does not equal 100 * sizeof(int) because the sizeof operator, when applied to a parameter declared to have array or function type, yields the size of the adjusted (pointer) type , even if the parameter declaration specifies a length:

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

ARR01-C

highHigh

probableProbable

lowLow

P18

L1

Automated Detection

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect violations of the recommendation but cannot distinguish between incomplete array declarations and pointer declarations

LDRA tool suite

Include Page
LDRA_V
LDRA_V

401 S

Partially implemented

Splint

Include Page
Splint_V
Splint_V

 

 

...