[mlpack-git] master: Fix invalid accesses by reordering loop conditionals. (093579b)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:45:10 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125

>---------------------------------------------------------------

commit 093579bd391c104cb07bd5225a7a833610e497d5
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Oct 27 14:01:32 2015 -0700

    Fix invalid accesses by reordering loop conditionals.


>---------------------------------------------------------------

093579bd391c104cb07bd5225a7a833610e497d5
 src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split_impl.hpp | 4 ++--
 src/mlpack/methods/hoeffding_trees/numeric_split_info.hpp           | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split_impl.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split_impl.hpp
index 8f72d17..b8bb34f 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split_impl.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split_impl.hpp
@@ -67,7 +67,7 @@ void HoeffdingNumericSplit<FitnessFunction, ObservationType>::Train(
     {
       // What bin does the point fall into?
       size_t bin = 0;
-      while (observations[i] > splitPoints[bin] && bin < bins - 1)
+      while (bin < bins - 1 && observations[i] > splitPoints[bin])
         ++bin;
 
       sufficientStatistics(labels[i], bin)++;
@@ -77,7 +77,7 @@ void HoeffdingNumericSplit<FitnessFunction, ObservationType>::Train(
   // If we've gotten to here, then we need to add the point to the sufficient
   // statistics.  What bin does the point fall into?
   size_t bin = 0;
-  while (value > splitPoints[bin] && bin < bins - 1)
+  while (bin < bins - 1 && value > splitPoints[bin])
     ++bin;
 
   sufficientStatistics(label, bin)++;
diff --git a/src/mlpack/methods/hoeffding_trees/numeric_split_info.hpp b/src/mlpack/methods/hoeffding_trees/numeric_split_info.hpp
index eaac2db..5f946d4 100644
--- a/src/mlpack/methods/hoeffding_trees/numeric_split_info.hpp
+++ b/src/mlpack/methods/hoeffding_trees/numeric_split_info.hpp
@@ -25,7 +25,7 @@ class NumericSplitInfo
   {
     // What bin does the point fall into?
     size_t bin = 0;
-    while (value > splitPoints[bin] && bin < splitPoints.n_elem)
+    while (bin < splitPoints.n_elem && value > splitPoints[bin])
       ++bin;
 
     return bin;



More information about the mlpack-git mailing list