Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
char *p = (char *)malloc(10);

Compliant Solution

By ommiting omitting the explicit cast to a pointer, the compiler can determine that an int is attempting to be assigned to a pointer type and will generate a warning that may easily be corrected.

Code Block
bgColor#ccccff
#include <stdlib.h>
/* ... */
char *p = malloc(10);

Exceptions

The return value from malloc() may be cast in C code that needs to be compatible with C++, where explicit casts from void * are required.

Risk Assessment

Explicitly casting the return value of malloc() eliminates the warning for the implicit declaration of malloc().

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

MEM02-A

1 (low)

1 (unlikely)

3 (low)

P3

L3

...