MISRAC2012-Rule-1.3_m
In this section:
Synopsis
(Required) There shall be no occurrence of undefined or critical unspecified behavior.
Enabled by default
Yes
Severity/Certainty
Low/High

Full description
A function pointer is used in an invalid context.
Coding standards
- CERT EXP16-C
Do not compare function pointers to constant values
- CWE 480
Use of Incorrect Operator
Code examples
The following code example fails the check and will give a warning:
int foo(int x, int y){
return x+y;
}
int foo2(int x, int y) {
if (foo)
return (foo)(x,y);
if (foo && foo2)
return (foo)(x,y);
return 0;
}
The following code example passes the check and will not give a warning about this issue:
typedef int (*fptr)(int,int);
int f_add(int x, int y) {
return x+y;
}
int f_sub(int x, int y) {
return x-y;
}
int foo(int opcode, int x, int y) {
fptr farray[2];
farray[0] = f_add;
farray[1] = f_sub;
return (farray[opcode])(x,y);
}
int foo2(fptr f1, fptr f2) {
if (f1 == f2)
return 1;
else
return 0;
}