]> granicus.if.org Git - graphviz/commitdiff
sparse SparseMatrix_coordinate_form_add_entry: abbreviate no-op 'MAX' call
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 28 Aug 2022 20:23:01 +0000 (13:23 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 31 Aug 2022 00:12:49 +0000 (17:12 -0700)
d1d1ae30865c14bb7e6a75f8772543c10419e48b seems to have incorrectly assumed
multiplication has a higher precedence than casts. In reality, it is the
opposite, meaning the first parameter to this `MAX` call was always 0. So the
entire expression would evaluate to 10. Empirically this seems to have been fine
since this code has been in use for over a decade with no specific problems
blamed on this area. So lets just abbreviate it into what it evaluates to.

Gitlab: fixes #2269

lib/sparse/SparseMatrix.c

index 3ba6852c6f9081d3e78c2463cf71162ead631362..924ad40eafe53717c440703ba02ce8fbb94d6bc1 100644 (file)
@@ -1464,7 +1464,7 @@ SparseMatrix SparseMatrix_coordinate_form_add_entry(SparseMatrix A, int irn,
 
   if (nz + nentries >= A->nzmax){
     nzmax = nz + nentries;
-     nzmax = MAX(10, (int) 0.2*nzmax) + nzmax;
+    nzmax += 10;
     A = SparseMatrix_realloc(A, nzmax);
   }
   A->ia[nz] = irn;