]> granicus.if.org Git - graphviz/commitdiff
neatogen compute_apsp_dijkstra: use cgraph wrappers for allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 18 Nov 2022 01:14:41 +0000 (17:14 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 3 Dec 2022 20:48:18 +0000 (12:48 -0800)
The lib/cgraph/alloc.h wrappers are similar to the older lib/common/memory.h
wrappers except (1) they are header-only and (2) they live in a directory
(cgraph) that is at the root of the dependency tree. The long term plan is to
replace all use of lib/common/memory.h with lib/cgraph/alloc.h.

We can also squash a -Wsign-conversion warning at the same time, noting that the
square of a signed number is always non-negative.

lib/neatogen/kkutils.c

index 82502f2eeacd99898912974b919846ffee2404f2..f9db09c89f38ebe81b76e512438f2b253057f89a 100644 (file)
@@ -8,7 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
-
+#include <cgraph/alloc.h>
 #include <neatogen/bfs.h>
 #include <neatogen/dijkstra.h>
 #include <neatogen/kkutils.h>
@@ -56,11 +56,9 @@ void empty_neighbors_vec(vtx_data * graph, int vtx, int *vtx_vec)
 static DistType **compute_apsp_dijkstra(vtx_data * graph, int n)
 {
     int i;
-    DistType *storage;
-    DistType **dij;
 
-    storage = N_GNEW(n * n, DistType);
-    dij = N_GNEW(n, DistType *);
+    DistType *storage = gv_calloc((size_t)(n * n), sizeof(DistType));
+    DistType **dij = gv_calloc(n, sizeof(DistType*));
     for (i = 0; i < n; i++)
        dij[i] = storage + i * n;