FPT-literal
In this section:
Synopsis
A function pointer that refers to a literal address is dereferenced.
Enabled by default
No
Severity/Certainty
High/Medium

Full description
A function pointer that refers to a literal address is dereferenced. A literal address is always invalid as a function pointer, and dereferencing it is an illegal memory access that might cause the application to crash.
Coding standards
This check does not correspond to any coding standard rules.
Code examples
The following code example fails the check and will give a warning:
#include <stdlib.h>
typedef void (*fn)(int);
void baz(int x){
++x;
}
void example(void) {
fn bar = NULL;
/* ... */
bar(1); //ERROR
}
The following code example passes the check and will not give a warning about this issue:
#include <stdlib.h>
typedef void (*fn)(int);
void baz(int x){
++x;
}
void example(void) {
fn bar = NULL;
/* ... */
bar = baz;
bar(1);
}