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.VOID_PTR_TO_INT.2012

Cast between a pointer to void and an arithmetic type.

MISRA C 2012 Rule 11.6: A cast shall not be performed between pointer to void and an 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

Rationale

Conversion of an integer into a pointer to void may result in a pointer that is not correctly aligned, resulting in undefined behaviour.

Conversion of a pointer to void into an integer may produce a value that cannot be represented in the chosen integer type resulting in undefined behaviour.

Conversion between any non-integer arithmetic type and pointer to void is undefined.

Exception

An integer constant expression with value 0 may be cast into pointer to void.

Example

void     * p;
uint32_t   u;

/* Non-compliant - implementation-defined */
p = ( void * ) 0x1234u;

/* Non-compliant - undefined              */
p = ( void * ) 1024.0f;

/* Non-compliant - implementation-defined */
u = ( uint32_t ) p;