Versions Compared

Key

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

...

Different implementations have different precision limitations, and to keep code portable, floating-point variables must not be used as the loop induction variable. See Goldberg's work for an introduction to this topic [Goldberg 1991].

For the purpose of this rule, a loop counter is an induction variable that is used as an operand of a comparison expression that is used as the controlling expression of a do, while, or for loop. An induction variable is a variable that gets increased or decreased by a fixed amount on every iteration of a loop [Aho 1986]. Furthermore, the change to the variable must occur directly in the loop body (rather than inside a function executed within the loop).

...

The use of floating-point variables as loop counters can result in  unexpected behavior .

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

FLP30-C

Low

Probable

Low

P6

L2

Automated Detection

Tool

Version

Checker

Description

Astrée
Include Page
Astrée_V
Astrée_V
for-loop-floatFully checked
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC-FLP30Fully implemented
Clang
Include Page
Clang_39_V
Clang_39_V
cert-flp30-cChecked by clang-tidy
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V
LANG.STRUCT.LOOP.FPCFloat-typed loop counter
Compass/ROSE

 

 




Coverity
Include Page
Coverity_V
Coverity_V

MISRA C 2004 Rule 13.4

MISRA C 2012 Rule 14.1

Implemented
 
ECLAIR
Include Page
ECLAIR_V
ECLAIR_V
CC2.FLP30Fully implemented
Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C3339, C3340, C3342

C++4234


Klocwork
Include Page
Klocwork_V
Klocwork_V
MISRA.FOR.COUNTER.FLT
LDRA tool suite
Include Page
LDRA_V
LDRA_V

39 S

Fully implemented

Parasoft C/C++test
9.5MISRA-065
Include Page
Parasoft_V
Parasoft_V
CERT_C-FLP30-a
Do not use floating point variables as loop counters
PC-lint Plus

Include Page
PC-lint Plus_V
PC-lint Plus_V

9009

Fully supported

Polyspace Bug Finder

Include Page

Fully implemented

Polyspace Bug Finder

R2016aMISRA2012-RULE-14_1, MISRA2012-DIR-1_1Fully implementedPRQA QA-C Include Page

_V
Polyspace Bug Finder_V

CERT C: Rule FLP30-C

Checks for use of float variable as loop counter (rule fully covered)

PVS-Studio

Include Page
PVS-Studio_V
PVS-Studio_V

V1034
RuleChecker
Include Page
RuleChecker_V
RuleChecker_V
for-loop-floatFully checked
PRQA QA-C_vPRQA QA-C_v3340Partially implemented
SonarQube C/C++ Plugin

Include Page
SonarQube C/C++ Plugin_V
SonarQube C/C++ Plugin_V

S2193Fully implemented
TrustInSoft Analyzer

Include Page
TrustInSoft Analyzer_V
TrustInSoft Analyzer_V

non-terminatingExhaustively detects non-terminating statements (see one compliant and one non-compliant example).

Related Vulnerabilities

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

Related Guidelines

Key here (explains table format and definitions)

Taxonomy

Taxonomy item

Relationship

CERT C
SEI CERT C++ Coding Standard
FLP30-CPP. Do not use floating-point variables as loop countersPrior to 2018-01-12: CERT: Unspecified Relationship
CERT Oracle Secure Coding Standard for JavaNUM09-J. Do not use floating-point variables as loop countersPrior to 2018-01-12: CERT: Unspecified Relationship
ISO/IEC TR 24772:2013Floating-Point Arithmetic [PLF]Prior to 2018-01-12: CERT: Unspecified Relationship
MISRA C:2012Directive 1.1 (required)Prior to 2018-01-12: CERT: Unspecified Relationship
MISRA C:2012Rule 14.1 (required)Prior to 2018-01-12: CERT: Unspecified Relationship

Bibliography

...


...

Image Modified Image Modified Image Modified