]> granicus.if.org Git - graphviz/commitdiff
sparse SparseMatrix_get_augmented: use cgraph wrappers for allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 15 Sep 2022 01:09:49 +0000 (18:09 -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 5f1a8574494e4fa3d723778bb33454afa5b53c27..321958796f307054b17a70540f6a1944609188a3 100644 (file)
@@ -2113,13 +2113,13 @@ SparseMatrix SparseMatrix_get_augmented(SparseMatrix A){
   SparseMatrix B = NULL;
   if (!A) return NULL;
   if (nz > 0){
-    irn = MALLOC(sizeof(int)*((size_t)nz)*2);
-    jcn = MALLOC(sizeof(int)*((size_t)nz)*2);
+    irn = gv_calloc((size_t)nz * 2, sizeof(int));
+    jcn = gv_calloc((size_t)nz * 2, sizeof(int));
   }
 
   if (A->a){
     assert(A->size != 0 && nz > 0);
-    val = MALLOC(A->size*2*((size_t)nz));
+    val = gv_calloc(2 * (size_t)nz, A->size);
     memcpy(val, A->a, A->size*((size_t)nz));
     memcpy(((char*) val) + ((size_t)nz)*A->size, A->a, A->size*((size_t)nz));
   }