From 8d5d25da2eb8e9bc73473088ec730bcc0ea7bfa1 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 1 Apr 2019 11:22:55 +0200 Subject: [PATCH] fix crash when checking an empty error message of an exception --- src/Base/Interpreter.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index 927a4e101b..93f726d3c6 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -354,13 +354,15 @@ void InterpreterSingleton::runInteractiveString(const char *sCmd) PyErr_Fetch(&errobj, &errdata, &errtraceback); RuntimeError exc(""); // do not use PyException since this clears the error indicator + if (errdata) { #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_Check(errdata)) - exc.setMessage(PyUnicode_AsUTF8(errdata)); + if (PyUnicode_Check(errdata)) + exc.setMessage(PyUnicode_AsUTF8(errdata)); #else - if (PyString_Check(errdata)) - exc.setMessage(PyString_AsString(errdata)); + if (PyString_Check(errdata)) + exc.setMessage(PyString_AsString(errdata)); #endif + } PyErr_Restore(errobj, errdata, errtraceback); if (PyErr_Occurred()) PyErr_Print();