From 5302e39f69c3606bf5646eff23ab46847b6a3156 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 3 Oct 2023 14:35:48 -0400 Subject: [PATCH] avoid segfaults when accessing lammps_last_thermo() --- src/library.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index f89fdaebf0..7b0d8ef91b 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -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();