fix for Bug #3085:
authorVladislav Vinogradov <vlad.vinogradov@itseez.com>
Thu, 13 Jun 2013 06:22:56 +0000 (10:22 +0400)
committerVladislav Vinogradov <vlad.vinogradov@itseez.com>
Thu, 13 Jun 2013 06:22:56 +0000 (10:22 +0400)
weights array is only allocated for (l_count+1) elements,
but then weights[l_count+1] element is accessed.

modules/ml/src/ann_mlp.cpp

index bf85425..7323ab5 100644 (file)
@@ -251,7 +251,7 @@ void CvANN_MLP::create( const CvMat* _layer_sizes, int _activ_func,
     buf_sz += (l_dst[0] + l_dst[l_count-1]*2)*2;
 
     CV_CALL( wbuf = cvCreateMat( 1, buf_sz, CV_64F ));
-    CV_CALL( weights = (double**)cvAlloc( (l_count+1)*sizeof(weights[0]) ));
+    CV_CALL( weights = (double**)cvAlloc( (l_count+2)*sizeof(weights[0]) ));
 
     weights[0] = wbuf->data.db;
     weights[1] = weights[0] + l_dst[0]*2;