]> granicus.if.org Git - graphviz/commitdiff
sparse SparseMatrix_distance_matrix: use cgraph wrappers for allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 15 Sep 2022 01:14:10 +0000 (18:14 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 20 Sep 2022 14:36:59 +0000 (07:36 -0700)
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.

lib/sparse/SparseMatrix.c

index f867687415401e16fb1f4b02c11da92f4e278a08..922e30d3a001f4256efbe6e8a52fb6cbc05af198 100644 (file)
@@ -2385,7 +2385,7 @@ int SparseMatrix_distance_matrix(SparseMatrix D0, int weighted, double **dist0){
 
   assert(m == n);
 
-  if (!(*dist0)) *dist0 = MALLOC(sizeof(double)*n*n);
+  if (!(*dist0)) *dist0 = gv_calloc(n * n, sizeof(double));
   for (i = 0; i < n*n; i++) (*dist0)[i] = -1;
 
   if (!weighted){
@@ -2399,7 +2399,7 @@ int SparseMatrix_distance_matrix(SparseMatrix D0, int weighted, double **dist0){
       }
      }
  } else {
-    list = MALLOC(sizeof(int)*n);
+    list = gv_calloc(n, sizeof(int));
     for (k = 0; k < n; k++){
       dist = &((*dist0)[k*n]);
       flag = Dijkstra(D, k, dist, &nlist, list, &dmax);