C and C++


LANG.CAST.PC.DATA2FN : Conversion to Function Pointer

Summary

A value of non-function-pointer type is cast or coerced to a function pointer type.

Properties

Class Name Conversion to Function Pointer
Significance security
Mnemonic LANG.CAST.PC.DATA2FN
Categories
MisraC2023 MisraC2023:11.1 Conversions shall not be performed between a pointer to a function and any other type
Misra2012 Misra2012:11.1 Conversions shall not be performed between a pointer to a function and any other type
AUTOSARC++14 AUTOSARC++14:M8-4-4 A function identifier shall either be used to call the function or it shall be preceded by &.
MisraC++2008 MisraC++2008:8-4-4 A function identifier shall either be used to call the function or it shall be preceded by &.
MisraC++2023 MisraC++2023:7.11.3 A conversion from function type to pointer-to-function type shall only occur in appropriate contexts
  MisraC++2023:8.2.4 Casts shall not be performed between a pointer to a function and any other type
CWE CWE:704 Incorrect Type Conversion or Cast
TS17961 TS17961:5.1-ptrcomp 5.1. Accessing an object through a pointer to an incompatible type
  TS17961:5.6-argcomp 5.6. Calling functions with incorrect arguments
JSF++ JSF++:182 Type casting from any type to or from pointers shall not be used.
  JSF++:183 Every possible measure should be taken to avoid type casting.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Conversion to Function Pointer"

Example

typedef int (*TakesIntRetsInt)(int) ;

int PC_DATA2FN( int x){
    TakesIntRetsInt f = (TakesIntRetsInt) x; /* 'Conversion to Function Pointer' warning issued here */
    TakesIntRetsInt g =  x;                  /* 'Conversion to Function Pointer' warning issued here */
    return (f(5) + g(5));
}

See also

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.