From 8f38bccc80c6d8c5666882ec89e6693ed6e70f31 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 30 Jul 2022 09:21:45 -0700 Subject: [PATCH] pathplan: remove 'mymalloc' wrapper The calling code does not rely on the semantics of `malloc` returning `NULL` when called with a 0 size. It unconditionally frees these arrays in `Pobsclose` so allocations returning a non-`NULL` pointer for 0-sized allocations (which Glibc typically does) is fine. Maintaining a wrapper that enforces this is unnecessary. --- lib/pathplan/cvt.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/pathplan/cvt.c b/lib/pathplan/cvt.c index d2ed71647..f22bd5d58 100644 --- a/lib/pathplan/cvt.c +++ b/lib/pathplan/cvt.c @@ -27,18 +27,6 @@ static void gasp_print_polyline(Ppolyline_t * route); static void gasp_print_bezier(Ppolyline_t * route); #endif -static void *mymalloc(size_t newsize) -{ - void *rv; - - if (newsize > 0) - rv = malloc(newsize); - else - rv = NULL; - return rv; -} - - vconfig_t *Pobsopen(Ppoly_t ** obs, int n_obs) { vconfig_t *rv; @@ -54,10 +42,10 @@ vconfig_t *Pobsopen(Ppoly_t ** obs, int n_obs) n = 0; for (poly_i = 0; poly_i < n_obs; poly_i++) n += obs[poly_i]->pn; - rv->P = mymalloc(n * sizeof(Ppoint_t)); - rv->start = mymalloc((n_obs + 1) * sizeof(int)); - rv->next = mymalloc(n * sizeof(int)); - rv->prev = mymalloc(n * sizeof(int)); + rv->P = malloc(n * sizeof(Ppoint_t)); + rv->start = malloc((n_obs + 1) * sizeof(int)); + rv->next = malloc(n * sizeof(int)); + rv->prev = malloc(n * sizeof(int)); rv->N = n; rv->Npoly = n_obs; -- 2.40.0