V2589. MISRA. Casts between a pointer and a non-integer arithmetic type should not be performed.
This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.
This diagnostic rule is relevant only for C.
The conversion between a non-integer arithmetic type and a pointer may lead to undefined behavior.
The MISRA C standard defines its own type model, called the essential type model.
The conversion between essential Boolean
, essential character
, or essential enum
type and a pointer may result in a misaligned pointer, which, in turn, may lead to undefined behavior.
The example:
enum Nums
{
ONE,
TWO,
....
};
double* bar(Nums num)
{
....
return (double*)num;
}
The conversion between a pointer and essential types described above may result in a value unrepresentable within the destination essential type, which also may lead to undefined behavior.
The example:
void foo(void)
{
....
char *a = "something";
char b = a;
....
}
The conversion between the essential floating
type and a pointer may lead to undefined behavior.
The example:
void foo(short *p)
{
// ....
float f = (float) p;
// ....
}
This diagnostic is classified as:
|