safe array

add extra safety checks to array_realloc
This commit is contained in:
2024-08-07 23:17:06 +02:00
parent 1d1d9c62cb
commit eeef4e4752

View File

@@ -49,6 +49,15 @@ array_t *array_realloc(array_t* arr, size_t rows)
fprintf(stderr, "%s: ptr dereferences to NULL\n", __func__);
return NULL;
}
if (arr->rows > rows)
{
fprintf(stderr, "%s: arr->rows (%d) > rows (%d)\n", __func__, arr->rows, rows);
return NULL;
}
if (arr->rows == rows)
{
return arr;
}
array_t *new_arr = realloc(arr, sizeof(array_t) + (arr->size * rows - 1));
if (!new_arr)