enum { MAX_TABLE_LENGTH = 256 };
int create_table(size_t length) {
size_t table_length;
char **table;
if (length == 0 || length > MAX_TABLE_LENGTH) {
/* Handle invalid length */
}
/*
* The wrap check has been omitted based on the assumption
* that MAX_TABLE_LENGTH * sizeof(char *) cannot exceed
* SIZE_MAX. If this assumption is not valid, a check must
* be added.
*/
assert(length <= SIZE_MAX/sizeof(char *));
table_length = length * sizeof(char *);
table = (char **)malloc(table_length);
if (table == NULL) {
/* Handle error condition */
}
/* ... */
return 0;
}
|