JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
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
MisraC2025 MisraC2025:11.1 Conversions shall not be performed between a pointer to a function and any other type
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 Accessing an object through a pointer to an incompatible type
  TS17961:5.6-argcomp 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
                                              * ('Bad Initializer Type' warning also issued)
                                              */
    return (f(5) + g(5));
}

See also

Relevant Configuration File Parameters

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

 

To report problems with this documentation, please visit https://support.codesecure.com/.