@@ -199,6 +199,10 @@ class MixedEffectsShapeMatrix : public LegacyShapeMatrix {
199199 }
200200 }
201201
202+ #if defined(__GNUC__) && !defined(__clang__)
203+ #pragma GCC diagnostic push
204+ #pragma GCC diagnostic ignored "-Walloc-size-larger-than="
205+ #endif
202206 void EstimateParameters () {
203207 // std::cout << "Estimating params" << std::endl;
204208 // std::cout << "Explanatory: " << m_Expl << std::endl;
@@ -210,6 +214,14 @@ class MixedEffectsShapeMatrix : public LegacyShapeMatrix {
210214 this ->m_NumIndividuals = num_shapes / this ->GetTimeptsPerIndividual ();
211215 int nr = X.rows (); // number of points*3
212216
217+ // Guard against invalid m_NumIndividuals
218+ if (m_NumIndividuals <= 0 ) {
219+ return ;
220+ }
221+
222+ // Use local variable to help compiler understand value is positive
223+ const size_t num_individuals = static_cast <size_t >(m_NumIndividuals);
224+
213225 // set the sizes of random slope and intercept matrix
214226 m_SlopeRand.set_size (m_NumIndividuals, nr); // num_groups X num_points*3
215227 m_InterceptRand.set_size (m_NumIndividuals, nr); // num_groups X num_points*3
@@ -228,8 +240,8 @@ class MixedEffectsShapeMatrix : public LegacyShapeMatrix {
228240 identity_2.set_size (2 , 2 );
229241 identity_2.set_identity ();
230242 vnl_matrix<double >*Ws = NULL , *Vs = NULL ;
231- Ws = new vnl_matrix<double >[m_NumIndividuals ];
232- Vs = new vnl_matrix<double >[m_NumIndividuals ];
243+ Ws = new vnl_matrix<double >[num_individuals ];
244+ Vs = new vnl_matrix<double >[num_individuals ];
233245 for (int i = 0 ; i < m_NumIndividuals; i++) {
234246 Vs[i].set_size (m_TimeptsPerIndividual, m_TimeptsPerIndividual);
235247 Ws[i].set_size (m_TimeptsPerIndividual, m_TimeptsPerIndividual);
@@ -319,6 +331,9 @@ class MixedEffectsShapeMatrix : public LegacyShapeMatrix {
319331 // printf ("random: slopes %g %g, intercepts %g %g", m_SlopeRand(0,0), m_SlopeRand(1,0), m_InterceptRand(0,0),
320332 // m_InterceptRand(1,0));
321333 }
334+ #if defined(__GNUC__) && !defined(__clang__)
335+ #pragma GCC diagnostic pop
336+ #endif
322337
323338 //
324339 void Initialize () {
0 commit comments