Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2012-Rule-21.17_a

In this section:
Synopsis

(Mandatory) Use of the string handling functions from <string.h> shall not result in accesses beyond the bounds of the objects referenced by their pointer parameters.

Enabled by default

Yes

Severity/Certainty

High/Medium

highmedium.png
Full description

A call to strlen might cause destination buffer overrun.

Coding standards
MISRA C:2012 Rule-21.17

(Mandatory) Use of the string handling functions from <string.h> shall not result in accesses beyond the bounds of the objects referenced by their pointer parameters

Code examples

The following code example fails the check and will give a warning:

#include <string.h>
int example(void) {
    char string[3] = "Foo";
    return strlen(string);
}

The following code example passes the check and will not give a warning about this issue:

#include <string.h>
int example(void) {
    char string[4] = "Foo";
    return strlen(string);
}