From: Matthew Fernandez Date: Mon, 26 Dec 2022 05:41:23 +0000 (-0800) Subject: pathplan: replace unchecked allocation calls with cgraph wrappers X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a0c69f09e31b2bf3145605fc4da128920f9f01f;p=graphviz 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 --- 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;