Versions Compared

Key

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

...

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

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

  if (sizeof(char *) > SIZE_MAX/size) {
   /* handle overflow */
  }/* Overflow check omitted because overflow is impossible given 
     MAX_TABLE_SIZE of 256 and sizeof(char *) of 8 or below */

  size_t table_size = size * sizeof(char *);
  if (size == 0 || size > MAX_TABLE_SIZE) {
    /* Handle invalid size */
  }

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

...