From: Matthew Fernandez Date: Sat, 30 Jul 2022 16:47:54 +0000 (-0700) Subject: pathplan Pobsopen: call 'calloc' instead of 'malloc' when allocating arrays X-Git-Tag: 5.0.1~21^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3442b4b496dcbe05a3d40c85c515bfd80a4e2d7;p=graphviz pathplan Pobsopen: call 'calloc' instead of 'malloc' when allocating arrays This is the generally preferred way of doing this that avoids various pitfalls, such as integer overflow during multiplication. --- diff --git a/lib/pathplan/cvt.c b/lib/pathplan/cvt.c index aa1e7b52b..27ef7b29b 100644 --- a/lib/pathplan/cvt.c +++ b/lib/pathplan/cvt.c @@ -51,11 +51,11 @@ vconfig_t *Pobsopen(Ppoly_t ** obs, int n_obs) free(rv); return NULL; } - rv->P = malloc(n * sizeof(Ppoint_t)); + rv->P = calloc(n, sizeof(Ppoint_t)); assert(n_obs >= 0); - rv->start = malloc(((size_t)n_obs + 1) * sizeof(int)); - rv->next = malloc(n * sizeof(int)); - rv->prev = malloc(n * sizeof(int)); + rv->start = calloc((size_t)n_obs + 1, sizeof(int)); + rv->next = calloc(n, sizeof(int)); + rv->prev = calloc(n, sizeof(int)); rv->N = (int)n; rv->Npoly = n_obs;