Skip to main content

IAR Embedded Workbench for RISC-V 3.40

CERT-MSC37-C

In this section:
Synopsis

Ensure that control never reaches the end of a non-void function

Enabled by default

Yes

Severity/Certainty

High/Low

highlow.png
Full description

If control reaches the closing curly brace (}) of a non-void function without evaluating a return statement, using the return value of the function call is undefined behavior.

Coding standards
CERT MSC37-C

Ensure that control never reaches the end of a non-void function

Code examples

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

#include <string.h>
#include <stdio.h>

int checkpass(const char *password) {
  if (strcmp(password, "pass") == 0) {
    return 1;
  }
}

void func(const char *userinput) {
  if (checkpass(userinput)) {
    printf("Success\n");
  }
}

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

#include <string.h>
#include <stdio.h>

int checkpass(const char *password) {
  if (strcmp(password, "pass") == 0) {
    return 1;
  }
  return 0;
}

void func(const char *userinput) {
  if (checkpass(userinput)) {
    printf("Success!\n");
  }
}