changeset 25050:e376a35f168f stable

symfact.cc: Fix use of unitialized SparseBoolMatrix (bug #53507). * symbfact.cc (Fsymbfacc): Fill SparseBoolMatrix (i.e, initialize the data member), before calling transpose which reads the data. Replace for loop with std::fill_n for clarity. Add '#include "algorithm"' for access to std::fill_n.
author Rik <rik@octave.org>
date Thu, 29 Mar 2018 08:54:11 -0700
parents d298a0734d85
children 7c499f1426e5
files libinterp/dldfcn/symbfact.cc
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/symbfact.cc	Thu Mar 29 11:29:05 2018 -0400
+++ b/libinterp/dldfcn/symbfact.cc	Thu Mar 29 08:54:11 2018 -0700
@@ -27,6 +27,7 @@
 
 #include <cmath>
 
+#include <algorithm>
 #include <string>
 
 #include "CSparse.h"
@@ -295,7 +296,7 @@
         lnz += ColCount[j];
 
       // allocate the output matrix L (pattern-only)
-      SparseBoolMatrix L (n, n, lnz);
+      SparseBoolMatrix L (dim_vector (n, n), lnz);
 
       // initialize column pointers
       lnz = 0;
@@ -333,14 +334,13 @@
       // free workspace
       CHOLMOD_NAME(free_sparse) (&R, cm);
 
+      // fill L with one's
+      std::fill_n (L.xdata (), lnz, true);
+
       // transpose L to get R, or leave as is
       if (nargin < 3)
         L = L.transpose ();
 
-      // fill numerical values of L with one's
-      for (octave_idx_type p = 0 ; p < lnz ; p++)
-        L.xdata(p) = true;
-
       retval(4) = L;
     }