Skip to main content

IAR Embedded Workbench for RISC-V 3.40

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

highmedium.png
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);
}