Skip to main content

IAR Embedded Workbench for Arm 9.70.x

LIB-return-const

In this section:
Synopsis

The return value of a const standard library function is not used.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

The return value of a const standard library function is not used. Because this function is defined as const, the call itself has no side effects; the only yield is the return value. If this return value is not used, the function call is redundant. These functions are inspected: memchr(), strchr(), strpbrk(), strrchr(), strstr(), strtok(), gmtime(), getenv(), and bsearch(). Discarding the return values of these functions is harmless but might indicate a misunderstanding of the application logic or purpose.

Coding standards
CERT EXP12-C

Do not ignore values returned by functions

CWE 252

Unchecked Return Value

CWE 394

Unexpected Status Code or Return Value

Code examples

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

#include <string.h>

void example(void) {
  strchr("Hello", 'h');  // No effect
}

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

#include <string.h>

void example(void) {
  char* c = strchr("Hello", 'h');  //OK
}