...
Code Block | ||
---|---|---|
| ||
int create_table(size_t size) { char **table; if (sizeof(char *) > UINT_MAX/size) { /* handle overflow */ } size_t table_size = size * sizeof(char *); /* Check for integer overflow on multiplication */ malloc(table_size) if(table == NULL) { /* Handle error condition */ } /* ... */ return 0; } |
...
Code Block | ||
---|---|---|
| ||
enum { MAX_TABLE_SIZE = 256 }; int create_table(size_t size) { char **table; if (sizeof(char *) > UINT_MAX/size) { /* handle overflow */ } size_t table_size = size * sizeof(char *); /* Check for integer overflow on multiplication */ if(size == 0 || size > MAX_TABLE_SIZE) { /* Handle invalid size */ } table = malloc(table_size); if(table == NULL) { /* Handle error condition */ } /* ... */ return 0; } |
...