Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
size_t numbernum_elem = /* some initial value */;
int error_condition = 0;

/* initialize number */

int *x = (int *)malloc(number * sizeof(int));
if (x == NULL) {
  /* Handle Allocation Error */
}
/* ... */
if (error_condition == 1) {
  /* Handle Error Condition*/
  free(x);
}
/* ... */
free(x);

...

Code Block
bgColor#ccccff
size_t number num_elem = /* some initial value */;
int error_condition = 0;

/* initialize number */

if (number > SIZE_MAX/sizeof(int)) {
   /* handle overflow */
  }
int *x = (int *)malloc(number * sizeof(int));
if (x == NULL) {
  /* Handle Allocation Error */
}
/* ... */
if (error_condition == 1) {
  /* Handle Error Condition*/
}
/* ... */
free(x);
x = NULL;

...