Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated references from C11->C23

...

The C Standard, 6.3.2.3, paragraph 7 [ISO/IEC 9899:20112024], states

A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type. If the resulting pointer is not correctly aligned for the referenced the referenced type, the behavior is undefined.

See undefined behavior 25.

...

PTR.UNRELATED
MISRA.CAST.PTRINT
PORTING.CAST.FLTPNT
PORTING.CAST.PTR
PORTING.CAST.PTR.SIZE
PORTING.CAST.SIZEA cast should not be performed between a pointer to object type and a different pointer to object wrong allocated object size for cast

Tool

Version

Checker

Description

Astrée
Include Page
Astrée_V
Astrée_V
pointer-cast-alignmentFully checked
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC-EXP36
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

LANG.CAST.PC.OBJ

Cast: Object Pointers

Compass/ROSE

Can detect violations of this rule. However, it does not flag explicit casts to void * and then back to another pointer type

Coverity
Include Page
Coverity_V
Coverity_V

MISRA C 2004 Rule 11.4

MISRA C 2012 Rule 11.1

MISRA C 2012 Rule 11.2

MISRA C 2012 Rule 11.5

MISRA C 2012 Rule 11.7

Implemented
Cppcheck Premium

Include Page
Cppcheck Premium_V
Cppcheck Premium_V

premium-cert-exp36-cPartially implemented

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

CC2.EXP36

Fully implemented
EDG


GCC
Include Page
GCC_V
GCC_V

Can detect some violations of this rule when the -Wcast-align flag is used

Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C0326, C3305

C++3033, C++3038


Klocwork
 
Include Page
Klocwork_V
Klocwork_V
MISRA.CAST.OBJ_PTR_TO_OBJ_PTR.2012
LDRA tool suite
Include Page
LDRA_V
LDRA_V

94 S, 606 S

Partially implemented
Parasoft C/C++test
Include Page
Parasoft_V
Parasoft_V
CERT_C-EXP36-a

Do not cast pointers into more strictly aligned pointer types

PC-lint Plus

Include Page
PC-lint Plus_V
PC-lint Plus_V

2445

Partially supported: reports casts directly from a pointer to a less strictly aligned type to a pointer to a more strictly aligned

type

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rule EXP36-C

Checks for

source buffer misaligned with destination buffer (rule fully covered)

PRQA QA-C
Include Page
PRQA QA-C_vPRQA QA-C_v0326, 3305Fully implementedPRQA QA-C++
Include Page
cplusplus:PRQA QA-C++_Vcplusplus:PRQA QA-C++_V

3033, 3038

PVS-Studio

Include Page
PVS-Studio_V
PVS-Studio_V

V548, V641, V1032

RuleChecker

Include Page
RuleChecker_V
RuleChecker_V

pointer-cast-alignmentFully checked

Related Vulnerabilities

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

...

...