From: Matthew Fernandez Date: Sat, 30 Jul 2022 16:50:18 +0000 (-0700) Subject: pathplan Pobspath: replace an unchecked array 'malloc' with 'gv_calloc' X-Git-Tag: 5.0.1~21^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e99bf5094c2c60526ae2f5c70c3b6c862d79d1f9;p=graphviz pathplan Pobspath: replace an unchecked array 'malloc' with 'gv_calloc' This function has no way of reporting failure to the caller. So this turns an allocation failure from a messy crash into a more graceful exit. --- diff --git a/lib/pathplan/cvt.c b/lib/pathplan/cvt.c index 27ef7b29b..e7e7022d4 100644 --- a/lib/pathplan/cvt.c +++ b/lib/pathplan/cvt.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -128,7 +129,7 @@ int Pobspath(vconfig_t * config, Ppoint_t p0, int poly0, Ppoint_t p1, for (i = dad[config->N]; i != config->N + 1; i = dad[i]) opn++; opn++; - ops = malloc(opn * sizeof(Ppoint_t)); + ops = gv_calloc(opn, sizeof(Ppoint_t)); size_t j = opn - 1; ops[j--] = p1;