avoid segfaults when accessing lammps_last_thermo()

This commit is contained in:
Axel Kohlmeyer
2023-10-03 14:35:48 -04:00
parent bb01afc498
commit 5302e39f69

View File

@ -858,14 +858,17 @@ void *lammps_last_thermo(void *handle, const char *what, int index)
{
auto lmp = (LAMMPS *) handle;
void *val = nullptr;
if (!lmp->output) return val;
Thermo *th = lmp->output->thermo;
if (!th) return nullptr;
if (!th) return val;
const int nfield = *th->get_nfield();
BEGIN_CAPTURE
{
if (strcmp(what, "setup") == 0) {
val = (void *) &lmp->update->setupflag;
if (lmp->update)
val = (void *) &lmp->update->setupflag;
} else if (strcmp(what, "line") == 0) {
val = (void *) th->get_line();