[mlpack] 58/324: Fix #334 by ensuring vector accesses don't go out of bounds.

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:21:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit 2a7a018e9e1237bc5460fe70a62297e1887919d1
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Thu Jun 12 20:57:22 2014 +0000

    Fix #334 by ensuring vector accesses don't go out of bounds.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16687 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/det/dt_utils.cpp | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/mlpack/methods/det/dt_utils.cpp b/src/mlpack/methods/det/dt_utils.cpp
index 2db68e0..273ed98 100644
--- a/src/mlpack/methods/det/dt_utils.cpp
+++ b/src/mlpack/methods/det/dt_utils.cpp
@@ -214,8 +214,10 @@ DTree* mlpack::det::Trainer(arma::mat& dataset,
         minLeafSize);
 
     // Sequentially prune with all the values of available alphas and adding
-    // values for test values.
-    for (size_t i = 0; i < prunedSequence.size() - 2; ++i)
+    // values for test values.  Don't enter this loop if there are less than two
+    // trees in the pruned sequence.
+    for (size_t i = 0;
+         i < ((prunedSequence.size() < 2) ? 0 : prunedSequence.size() - 2); ++i)
     {
       // Compute test values for this state of the tree.
       double cvVal = 0.0;
@@ -242,8 +244,9 @@ DTree* mlpack::det::Trainer(arma::mat& dataset,
       cvVal += cvDTree->ComputeValue(testPoint);
     }
 
-    regularizationConstants[prunedSequence.size() - 2] += 2.0 * cvVal /
-        (double) dataset.n_cols;
+    if (prunedSequence.size() > 2)
+      regularizationConstants[prunedSequence.size() - 2] += 2.0 * cvVal /
+          (double) dataset.n_cols;
 
     test.reset();
     delete cvDTree;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list