Skip to content

Commit 0d46da9

Browse files
authored
Merge pull request #46350 from smuzaffar/ml-clang-ana-warn3
[ML][Clang]clang-analyzer, initialize memory and add protection against
2 parents 73cb482 + d97cd34 commit 0d46da9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

PhysicsTools/MVAComputer/src/ProcMLP.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <iterator>
2020
#include <vector>
2121
#include <cmath>
22+
#include <cassert>
2223

2324
#include "FWCore/Utilities/interface/Exception.h"
2425

@@ -100,14 +101,15 @@ namespace { // anonymous
100101
}
101102

102103
void ProcMLP::eval(ValueIterator iter, unsigned int n) const {
103-
double *tmp = (double *)alloca(2 * maxTmp * sizeof(double));
104+
double *tmp = (double *)calloc(2 * maxTmp, sizeof(double));
104105
bool flip = false;
105106

106107
for (double *pos = tmp; iter; iter++, pos++)
107108
*pos = *iter;
108109

109110
double *output = nullptr;
110111
for (std::vector<Layer>::const_iterator layer = layers.begin(); layer != layers.end(); layer++, flip = !flip) {
112+
assert(maxTmp >= layer->inputs);
111113
const double *input = &tmp[flip ? maxTmp : 0];
112114
output = &tmp[flip ? 0 : maxTmp];
113115
std::vector<double>::const_iterator coeff = layer->coeffs.begin();
@@ -123,6 +125,7 @@ namespace { // anonymous
123125

124126
for (const double *pos = &tmp[flip ? maxTmp : 0]; pos < output; pos++)
125127
iter(*pos);
128+
free(tmp);
126129
}
127130

128131
std::vector<double> ProcMLP::deriv(ValueIterator iter, unsigned int n) const {

0 commit comments

Comments
 (0)