Versions Compared

Key

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

...

Noncompliant Code Example

In this noncompliant code example, input_str is copied into dynamically allocated memory referenced by str. If malloc() fails, it returns a null pointer that is assigned to str. When str is dereferenced in memcpy(), the program behaves in an unpredictable manner.

...

To correct this error, ensure the pointer returned by malloc() is not NULLnull. This also ensures compliance with MEM32-C. Detect and handle memory allocation errors.

...