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

Conversion performed between a pointer to an incomplete type and a different type.

MISRA C 2012 Rule 11.2: Conversions shall not be performed between a pointer to an incomplete type and any other type

C90 [Undefined 29], C99 [Undefined 21, 22, 41]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

A pointer to an incomplete type shall not be converted into another type.

A conversion shall not be made into a pointer to incomplete type.

Although a pointer to void is also a pointer to an incomplete type, this rule does not apply to pointers to void as they are covered by Rule 11.5.

Rationale

Conversion into or from a pointer to an incomplete type may result in a pointer that is not correctly aligned, resulting in undefined behaviour.

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

Pointers to an incomplete type are sometimes used to hide the representation of an object. Converting a pointer to an incomplete type into a pointer to object would break this encapsulation.

Exception

  1. A null pointer constant may be converted into a pointer to an incomplete.
  2. A pointer to an incomplete type may be converted into void.

Example

struct s;                     /* Incomplete type                          */
struct t;                     /* A different incomplete type              */
struct s *sp;
struct t *tp;
int16_t *ip;

#include <stdlib.h>           /* To obtain macro NULL                     */

ip = ( int16_t * ) sp;        /* Non-compliant                            */
sp = ( struct s * ) 1234;     /* Non-compliant                            */
tp = ( struct t * ) sp;       /* Non-compliant - casting pointer into a
                               * different incomplete type                */
sp = NULL;                    /* Compliant - exception 1                  */

struct s *f ( void );

( void ) f ( );               /* Compliant - exception 2                  */