Skip to content

WIP:PrFitParams - Fix some out of bounds array access

Whilst running some tests, I stumbled over these compiler warnings

[1037/1210] Building CXX object Pr/PrFitParams/CMakeFiles/PrFitParams.dir/src/PrFitParameters.cpp.o
../Pr/PrFitParams/src/PrFitParameters.cpp: In member function 'bool PrFitParameters::updateParameters(MsgStream&)':
../Pr/PrFitParams/src/PrFitParameters.cpp:116:24: warning: array subscript is above array bounds [-Warray-bounds]
           m_mat[m_nbPar][i] = m_mat[im][i]*c1 + m_mat[jm][i]*c2;
           ~~~~~~~~~~~~~^
../Pr/PrFitParams/src/PrFitParameters.cpp:129:39: warning: array subscript is above array bounds [-Warray-bounds]
           m_mat[im][i] = m_mat[m_nbPar][i];
                          ~~~~~~~~~~~~~^
[1039/1210] Building CXX object Pr/PrFitParams/CMakeFiles/PrFitParams.dir/src/PrFitPolinomial.cpp.o
../Pr/PrFitParams/src/PrFitPolinomial.cpp: In member function 'bool PrFitPolinomial::solve()':
../Pr/PrFitParams/src/PrFitPolinomial.cpp:89:18: warning: array subscript is above array bounds [-Warray-bounds]
           mat[Dim][i] = mat[im][i]*c1 + mat[jm][i]*c2;
           ~~~~~~~^
../Pr/PrFitParams/src/PrFitPolinomial.cpp:102:31: warning: array subscript is above array bounds [-Warray-bounds]
           mat[im][i] = mat[Dim][i];
                        ~~~~~~~^
[1102/1210] Building CXX object Pr/PrMCTools/CMakeFiles/PrMCTools.dir/src/PrFitPolinomial.cpp.o
../Pr/PrMCTools/src/PrFitPolinomial.cpp: In member function 'bool PrFitPolinomial::solve()':
../Pr/PrMCTools/src/PrFitPolinomial.cpp:86:18: warning: array subscript is above array bounds [-Warray-bounds]
           mat[Dim][i] = mat[im][i]*c1 + mat[jm][i]*c2;
           ~~~~~~~^
../Pr/PrMCTools/src/PrFitPolinomial.cpp:99:31: warning: array subscript is above array bounds [-Warray-bounds]
           mat[im][i] = mat[Dim][i];
                        ~~~~~~~^

Looking at them, its clear they are real out of bounds access bugs. This MR should address them, by just extending the size of the containers. A tracking expert should look in detail though I think, as it's not clear to me what the intent of the code really is.... Theres also a little c++11 cleanup along the way.

I am also not sure why these do not seem to appear in the nighties tests... I'm running gcc 6.2 opt builds, with -O3 forced, in case thats part of it...

@decianm FYI

Merge request reports