...
Code Block | ||
---|---|---|
| ||
char** create_table(void) { const char* const lenstr = getenv("TABLE_SIZE"); const size_t length = lenstr ? strtoul(lenstr, 0NULL, 10) : 0; if (length > SIZE_MAX / sizeof(char *)) return NULL; /* indicate error to caller */ const size_t table_size = length * sizeof(char *); char** const table = (char **)malloc(table_size); if (table == NULL) return NULL; /* indicate error to caller */ /* initialize table... */ return table; } |
...
Code Block | ||
---|---|---|
| ||
enum { MAX_TABLE_LENGTH = 256 }; char** create_table(void) { const char* const lenstr = getenv("TABLE_SIZE"); const size_t length = lenstr ? strtoul(lenstr, 0NULL, 10) : 0; if (length == 0 || length > MAX_TABLE_LENGTH) return NULL; /* indicate error to caller */ const size_t table_size = length * sizeof(char *); char** const table = (char **)malloc(table_size); if (table == NULL) return NULL; /* indicate error to caller */ /* initialize table... */ return table; } |
...