From c048dc45532a643a6d8bcd425e8cc880ef00926a Mon Sep 17 00:00:00 2001 From: "Bastian M. Wojek" Date: Mon, 21 Feb 2011 20:44:06 +0000 Subject: [PATCH] Fixed accidental casting of a NULL pointer in msr2data---originally this was expected to lead to an exception (but obviously things are different) --- src/classes/PMsr2Data.cpp | 15 ++++++++------- src/msr2data.cpp | 30 ++++++++++++++++-------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/classes/PMsr2Data.cpp b/src/classes/PMsr2Data.cpp index 00797ea7b..0f44e5adf 100644 --- a/src/classes/PMsr2Data.cpp +++ b/src/classes/PMsr2Data.cpp @@ -1304,15 +1304,16 @@ bool PMsr2Data::PrepareGlobalInputFile(unsigned int tempRun, const string &msrOu // and do the fitting // check if MUSRFITPATH is set, if not issue a warning - string path; - try { - path = boost::lexical_cast(getenv("MUSRFITPATH")); - path.append("/"); - } - catch(boost::bad_lexical_cast &) { + string path(""); + char *pathPtr(getenv("MUSRFITPATH")); + if (pathPtr) { + path = boost::lexical_cast(pathPtr); + if (!path.empty()) { + path.append("/"); + } + } else { cerr << endl << ">> msr2data: **WARNING** The MUSRFITPATH environment variable is not set!"; cerr << endl << ">> msr2data: **WARNING** Please set it or at least ensure that musrfit can be found on the PATH!" << endl; - path = ""; } ostringstream oss; oss << path << "musrfit" << " " << *fRunVectorIter << "-OneRunFit" << fFileExtension << ".msr"; diff --git a/src/msr2data.cpp b/src/msr2data.cpp index 63dc7da35..bb57af86c 100644 --- a/src/msr2data.cpp +++ b/src/msr2data.cpp @@ -689,15 +689,16 @@ int main(int argc, char *argv[]) // and do the fitting if (!onlyInputCreation) { // check if MUSRFITPATH is set, if not issue a warning - string path; - try { - path = boost::lexical_cast(getenv("MUSRFITPATH")); - path.append("/"); - } - catch(boost::bad_lexical_cast &) { + string path(""); + char *pathPtr(getenv("MUSRFITPATH")); + if (pathPtr) { + path = boost::lexical_cast(pathPtr); + if (!path.empty()) { + path.append("/"); + } + } else { cerr << endl << ">> msr2data: **WARNING** The MUSRFITPATH environment variable is not set!"; cerr << endl << ">> msr2data: **WARNING** Please set it or at least ensure that musrfit can be found on the PATH!" << endl; - path = ""; } ostringstream oss; oss << path << "musrfit" << " " << strInfile.str() << " " << musrfitOptions; @@ -774,15 +775,16 @@ int main(int argc, char *argv[]) // and do the fitting if (!onlyInputCreation) { // check if MUSRFITPATH is set, if not issue a warning - string path; - try { - path = boost::lexical_cast(getenv("MUSRFITPATH")); - path.append("/"); - } - catch(boost::bad_lexical_cast &) { + string path(""); + char *pathPtr(getenv("MUSRFITPATH")); + if (pathPtr) { + path = boost::lexical_cast(pathPtr); + if (!path.empty()) { + path.append("/"); + } + } else { cerr << endl << ">> msr2data: **WARNING** The MUSRFITPATH environment variable is not set!"; cerr << endl << ">> msr2data: **WARNING** Please set it or at least ensure that musrfit can be found on the PATH!" << endl; - path = ""; } ostringstream oss; oss << path << "musrfit" << " " << strInfile.str() << " " << musrfitOptions;