From 0b9d91223964faad09e92e32eea77e4624be6d7b Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 9 Jan 2012 17:31:04 +0000 Subject: [PATCH] Fixed a segfault caused by an unprotected call to getenv() --- Cantera/src/base/ct2ctml.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Cantera/src/base/ct2ctml.cpp b/Cantera/src/base/ct2ctml.cpp index 4064ed126..e3ac5eb37 100644 --- a/Cantera/src/base/ct2ctml.cpp +++ b/Cantera/src/base/ct2ctml.cpp @@ -61,14 +61,19 @@ namespace ctml { static string pypath() { string s = "python"; const char* py = getenv("PYTHON_CMD"); + + // Try to source the "setup_cantera" script from the user's home + // directory in order to set PYTHON_CMD. if (!py) { const char* hm = getenv("HOME"); - string home = stripws(string(hm)); - string cmd = string(". ")+home - +string("/setup_cantera &> /dev/null"); + if (hm) { + string home = stripws(string(hm)); + string cmd = string(". ") + home + +string("/setup_cantera &> /dev/null"); system(cmd.c_str()); + } py = getenv("PYTHON_CMD"); - } + } if (py) { string sp = stripws(string(py)); if (sp.size() > 0) {