...
Code Block | ||
---|---|---|
| ||
size_t num_elem = /* some initial value */; int error_condition = 0; int *x = (int *)malloc(numbernum_elem * sizeof(int)); if (x == NULL) { /* Handle Allocation Error */ } /* ... */ if (error_condition == 1) { /* Handle Error Condition*/ free(x); } /* ... */ free(x); |
...
Code Block | ||
---|---|---|
| ||
size_t num_elem = /* some initial value */; int error_condition = 0; if (numbernum_elem > SIZE_MAX/sizeof(int)) { /* handle overflow */ } int *x = (int *)malloc(numbernum_elem * sizeof(int)); if (x == NULL) { /* Handle Allocation Error */ } /* ... */ if (error_condition == 1) { /* Handle Error Condition*/ } /* ... */ free(x); x = NULL; |
...