Versions Compared

Key

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

...

Code Block
bgColor#ccccff
langc
#include <stdlib.h>
#include <string.h>
 
enum { N1 = 4096 };

void* func(size_t n2) {
  if (n2 > SIZE_MAX / (N1 * sizeof (int))) {
    /* Prevent sizeof wrapping */
    return NULL;
  }

  typedef int A[n2][N1];

  A *array = malloc(sizeof (A));
  if (array == NULL) {
    /* Handle malloc failure */
    return NULL;
  } 

  for (size_t i = 0; i != n2; ++i)
    memset( array[i], 0, N1 * sizeof (int));

  return array;
}

Implementation Details

Microsoft

Variable length arrays are not supported by Microsoft compilers.

...