From 91bd7df8c1be1f4cb0d59207c99ba7c8afc24a43 Mon Sep 17 00:00:00 2001 From: Evgeny Agafonchikov Date: Fri, 20 Mar 2015 10:10:32 +0300 Subject: [PATCH] Fixing invalid opencv_test_ml calls --- modules/ml/src/tree.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/ml/src/tree.cpp b/modules/ml/src/tree.cpp index 537728336d..143e1fb916 100644 --- a/modules/ml/src/tree.cpp +++ b/modules/ml/src/tree.cpp @@ -286,7 +286,14 @@ int DTreesImpl::addTree(const vector& sidx ) int ssize = getSubsetSize(split.varIdx); split.subsetOfs = (int)subsets.size(); subsets.resize(split.subsetOfs + ssize); - memcpy(&subsets[split.subsetOfs], &w->wsubsets[wsplit.subsetOfs], ssize*sizeof(int)); + // This check verifies that subsets index is in the correct range + // as in case ssize == 0 no real resize performed. + // Thus memory kept safe. + // Also this skips useless memcpy call when size parameter is zero + if(ssize > 0) + { + memcpy(&subsets[split.subsetOfs], &w->wsubsets[wsplit.subsetOfs], ssize*sizeof(int)); + } } node.split = (int)splits.size(); splits.push_back(split);