You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. If the type of the operand is not a variable length array type the operand is not evaluated.

Non-Compliant Code Example

In this example, the variable a will still have a value 14 after b has been initialized.

int main(void) {
  int a = 14;
  int b = sizeof( a++ );
  printf("a, b = %d, %d.\n", a, b);  /* prints a, b = 14, 4. */
  return 0;
}

The expression a++ is not evaluated. Consequently, side effects in the expression are not executed.

Implementation Specific Details

This example compiles cleanly under Microsoft Visual Studio 2005 Version 8.0, with the /W4 option.

Priority: P4 Level: L3

If the object really is constant, the compiler may have put it in ROM or write-protected memory. Trying to modify such an object may lead to a program crash. This could allow an attacker to mount a denial-of-service attack.

Component

Value

Severity

1 (low)

Likelihood

2 (probable)

Remediation cost

2 (medium)

References

  • No labels