From 5a0c69f09e31b2bf3145605fc4da128920f9f01f Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 25 Dec 2022 21:41:23 -0800 Subject: [PATCH] pathplan: replace unchecked allocation calls with cgraph wrappers 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 --- lib/pathplan/visibility.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/pathplan/visibility.c b/lib/pathplan/visibility.c index 52d21bf2d..7294708e2 100644 --- a/lib/pathplan/visibility.c +++ b/lib/pathplan/visibility.c @@ -9,6 +9,7 @@ *************************************************************************/ #include +#include #include #include #include @@ -30,12 +31,10 @@ 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; -- 2.40.0