After the prior UB fixes, the #1999 example bottoms out in this code, failing
the second allocation call while trying to allocate ~938GB. The return values
for neither of these calls were checked, resulting in messy crashes when
scenarios like this occurred. This change swaps them for calls to the cgraph
allocation wrappers that exit gracefully on out-of-memory conditions.
Gitlab: #1999
*************************************************************************/
#include <assert.h>
+#include <cgraph/alloc.h>
#include <pathplan/vis.h>
#include <stdbool.h>
#include <stdlib.h>
static array2 allocArray(int V, int extra)
{
int i;
- array2 arr;
- COORD *p;
assert(V >= 0);
- arr = malloc((V + extra) * sizeof(COORD *));
- p = calloc((size_t)V * (size_t)V, sizeof(COORD));
+ array2 arr = gv_calloc(V + extra, sizeof(COORD*));
+ COORD *p = gv_calloc((size_t)V * (size_t)V, sizeof(COORD));
for (i = 0; i < V; i++) {
arr[i] = p;
p += V;