Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.CAST.OBJ_PTR_TO_NON_INT.2012

A cast between a pointer to object and a non-integer arithmetic type.

MISRA C 2012 Rule 11.7: A cast shall not be performed between pointer to object and a non-integer arithmetic type

C90 [Undefined 29; Implementation 24], C99 [Undefined 21, 41; Implementation J.3.7(1)]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

For the purposes of this rule a non-integer arithmetic type means one of:
  • Essentially Boolean;
  • Essentially character;
  • Essentially enum;
  • Essentially floating.

Rationale

Conversion of an essentially Boolean, essentially character or essentially enum type into a pointer to object may result in a pointer that is not correctly aligned, resulting in undefined behaviour.

Conversion of a pointer to object into an essentially Boolean, essentially character or essentially enum type may produce a value that cannot be represented in the chosen integer type resulting in undefined behaviour.

Conversion of a pointer to object into or from an essentially floating type results in undefined behaviour.

Example

int16_t * p;
float32_t f;

f = ( float32_t ) p;  /* Non-compliant */
p = ( int16_t * ) f;  /* Non-compliant */