From b54a9a95f06dbf6d2c98c7394b123dae7ef77441 Mon Sep 17 00:00:00 2001
From: Eckhard von Toerne <evt@physik.uni-bonn.de>
Date: Tue, 26 Mar 2013 09:49:21 +0000
Subject: [PATCH] bugfix, uncontrolled memory access in quantile calulation.
 Copied from dev, rev48934

git-svn-id: http://root.cern.ch/svn/root/trunk@48935 27541ba8-7e3a-0410-8455-c3a389f83636
---
 tmva/src/MethodBDT.cxx | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tmva/src/MethodBDT.cxx b/tmva/src/MethodBDT.cxx
index ab423c772a3..4ad72a92b20 100644
--- a/tmva/src/MethodBDT.cxx
+++ b/tmva/src/MethodBDT.cxx
@@ -1315,12 +1315,12 @@ Double_t TMVA::MethodBDT::GetWeightedQuantile(vector<  std::pair<Double_t, Doubl
    //calculates the quantile of the distribution of the first pair entries weighted with the values in the second pair entries
    Double_t temp = 0.0;
    std::sort(vec.begin(), vec.end());
-   Int_t i = 0;
-   while(temp <= norm*quantile){
-      temp += vec[i].second;
-      i++;
-   }
-      
+   UInt_t i = 0;
+   while(i<vec.size() && temp <= norm*quantile){
+     temp += vec[i].second;
+     i++;
+   }      
+   if (i >= vec.size()) return 0.; // prevent uncontrolled memory access in return value calculation 
    return vec[i].first;
 }
 
-- 
GitLab