Versions Compared

Key

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

...

This compliant solution defines a maximum size for the table of MAX_TABLE_SIZE or 256 elements. The lower bound for table size is checked against 0 to prevent malloc(0) (see MEM04-A. Do not make assumptions about the result of allocating 0 bytes). 

Code Block
bgColor#ccccff
enum { MAX_TABLE_SIZE = 256 };

int create_table(size_t size) {
  char **table;

  if(size == 0 || size > MAX_TABLE_SIZE) {
    /* Handle invalid size */
  }

  table = malloc(size * sizeof(char *));
  if(table == NULL) {
    /* Handle error condition */
  }
  /* ... */
  return 0;
}

...