...
| Code Block | ||
|---|---|---|
| ||
void function(size_t len) {
long *p;
if (len > SIZE_MAX / sizeof(long)) {
/* handle overflow */
}
p = malloc(len * sizeof(long));
if (p == NULL) {
/* handle error */
}
/* ... */
free(p);
}
|
Alternatively, the following idiom sizeof(*p) can be used to properly size the allocation:
...