From d62c6985caa240a60f542ac89b6c9cc5ccf91faa Mon Sep 17 00:00:00 2001 From: Benjamin Spencer Date: Fri, 29 Mar 2019 15:38:35 -0600 Subject: [PATCH] Avoid invalid pointer when there is no history data ref #59 --- src/materials/NEMLStress.C | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/materials/NEMLStress.C b/src/materials/NEMLStress.C index fea8a9bf..5ca1784d 100644 --- a/src/materials/NEMLStress.C +++ b/src/materials/NEMLStress.C @@ -74,8 +74,8 @@ NEMLStress::computeQpStress() double T_np1 = _temperature[_qp]; double T_n = _temperature_old[_qp]; - double * h_np1 = &(_hist[_qp][0]); - const double * const h_n = &(_hist_old[_qp][0]); + double * h_np1 = (_model->nhist() > 0 ? &(_hist[_qp][0]) : nullptr); + const double * const h_n = (_model->nhist() > 0 ? &(_hist_old[_qp][0]) : nullptr); double A_np1[36]; @@ -129,9 +129,12 @@ NEMLStress::initQpStatefulProperties() // Figure out initial history _hist[_qp].resize(_model->nhist()); - int ier = _model->init_hist(&(_hist[_qp][0])); - if (ier != neml::SUCCESS) - mooseError("Error initializing NEML history!"); + if (_model->nhist() > 0) + { + int ier = _model->init_hist(&(_hist[_qp][0])); + if (ier != neml::SUCCESS) + mooseError("Error initializing NEML history!"); + } _energy[_qp] = 0.0; _dissipation[_qp] = 0.0;