From de0938da39a2d27f68e67dc69d9c7694d691123c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 5 Apr 2019 23:24:43 -0400 Subject: [PATCH] avoid segfault when catching command line flag errors with EXCEPTIONS enabled --- src/error.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/error.cpp b/src/error.cpp index 913239ac49..7c2d3c5409 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -72,7 +72,9 @@ void Error::universe_all(const char *file, int line, const char *str) #ifdef LAMMPS_EXCEPTIONS // allow commands if an exception was caught in a run - update->whichflag = 0; + // update may be NULL when catching command line errors + + if (update) update->whichflag = 0; char msg[100]; snprintf(msg, 100, "ERROR: %s (%s:%d)\n", str, truncpath(file), line); @@ -97,7 +99,9 @@ void Error::universe_one(const char *file, int line, const char *str) #ifdef LAMMPS_EXCEPTIONS // allow commands if an exception was caught in a run - update->whichflag = 0; + // update may be NULL when catching command line errors + + if (update) update->whichflag = 0; char msg[100]; snprintf(msg, 100, "ERROR: %s (%s:%d)\n", str, truncpath(file), line); @@ -148,7 +152,9 @@ void Error::all(const char *file, int line, const char *str) #ifdef LAMMPS_EXCEPTIONS // allow commands if an exception was caught in a run - update->whichflag = 0; + // update may be NULL when catching command line errors + + if (update) update->whichflag = 0; char msg[100]; snprintf(msg, 100, "ERROR: %s (%s:%d)\n", str, truncpath(file), line); @@ -198,7 +204,9 @@ void Error::one(const char *file, int line, const char *str) #ifdef LAMMPS_EXCEPTIONS // allow commands if an exception was caught in a run - update->whichflag = 0; + // update may be NULL when catching command line errors + + if (update) update->whichflag = 0; char msg[100]; snprintf(msg, 100, "ERROR on proc %d: %s (%s:%d)\n", me, str, truncpath(file), line);