Skip to main content

IAR Embedded Workbench for RISC-V 3.40

ATH-sizeof-by-sizeof

In this section:
Synopsis

Multiplying sizeof by sizeof.

Enabled by default

Yes

Severity/Certainty

Medium/High

mediumhigh.png
Full description

sizeof is multiplied by sizeof. This is probably a programming mistake and might have been intended to be sizeof / sizeof. This code will not cause any errors, but the product of two sizeof results is not a useful value, and might indicate a misunderstanding of the intended behavior of the code.

Coding standards
CWE 480

Use of Incorrect Operator

Code examples

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

void foo(void)
{
  int x = sizeof(int) * sizeof(char);  //sizeof * sizeof
}

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

void foo(void)
{
  int x = sizeof(int) * 7;  //OK
}