From 5c69c21f56e916516cd68ee97c2674c1772ecd79 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Tue, 9 Aug 2016 12:43:13 +0200 Subject: [PATCH] should prevent crash if musrfit_startup.xml is NOT found anywhere. --- src/classes/PStartupHandler.cpp | 46 +++++++++++++++++++-------------- src/musrfit.cpp | 9 +++++-- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/classes/PStartupHandler.cpp b/src/classes/PStartupHandler.cpp index 9077629e..5660ea88 100644 --- a/src/classes/PStartupHandler.cpp +++ b/src/classes/PStartupHandler.cpp @@ -97,7 +97,6 @@ PStartupHandler::PStartupHandler() Char_t *home=0; Char_t musrpath[128]; Char_t startup_path_name[128]; - Bool_t found = false; strncpy(musrpath, "", sizeof(musrpath)); @@ -106,32 +105,39 @@ PStartupHandler::PStartupHandler() if (StartupFileExists(startup_path_name)) { fStartupFileFound = true; fStartupFilePath = TString(startup_path_name); - } else { // startup file is not found in the current directory + } + if (!fStartupFileFound) { // startup file not found in the current directory // check if the startup file is found under $HOME/.musrfit home = getenv("HOME"); if (home != 0) { - sprintf(musrpath, "%s/.musrfit", home); - found = true; - } - pmusrpath = getenv("MUSRFITPATH"); - if (!found) { - // check if the MUSRFITPATH system variable is set - if (pmusrpath != 0) { - if (strcmp(pmusrpath, "")) { // MUSRFITPATH variable set but empty - found = true; - } + sprintf(startup_path_name, "%s/.musrfit/musrfit_startup.xml", home); + if (StartupFileExists(startup_path_name)) { + fStartupFilePath = TString(startup_path_name); + fStartupFileFound = true; } } - if (!found) { // MUSRFITPATH not set or empty, will try default one - home = getenv("ROOTSYS"); + } + if (!fStartupFileFound) { // startup file not found in $HOME/.musrfit + // check if the MUSRFITPATH system variable is set + pmusrpath = getenv("MUSRFITPATH"); + if (pmusrpath != 0) { + sprintf(startup_path_name, "%s/musrfit_startup.xml", pmusrpath); + if (StartupFileExists(startup_path_name)) { + fStartupFilePath = TString(startup_path_name); + fStartupFileFound = true; + } + } + } + if (!fStartupFileFound) { // MUSRFITPATH not set or empty, will try $ROOTSYS/bin + home = getenv("ROOTSYS"); + if (home != 0) { sprintf(musrpath, "%s/bin", home); cerr << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl; - } - - sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath); - fStartupFilePath = TString(startup_path_name); - if (StartupFileExists(startup_path_name)) { - fStartupFileFound = true; + sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath); + if (StartupFileExists(startup_path_name)) { + fStartupFilePath = TString(startup_path_name); + fStartupFileFound = true; + } } } } diff --git a/src/musrfit.cpp b/src/musrfit.cpp index f5f5ac44..0bb0bd2d 100644 --- a/src/musrfit.cpp +++ b/src/musrfit.cpp @@ -614,10 +614,15 @@ int main(int argc, char *argv[]) } } } - startupHandler->SetStartupOptions(startup_options); + if (startupHandler) + startupHandler->SetStartupOptions(startup_options); // read msr-file - PMsrHandler *msrHandler = new PMsrHandler(filename, startupHandler->GetStartupOptions()); + PMsrHandler *msrHandler = 0; + if (startupHandler) + msrHandler = new PMsrHandler(filename, startupHandler->GetStartupOptions()); + else + msrHandler = new PMsrHandler(filename); status = msrHandler->ReadMsrFile(); if (status != PMUSR_SUCCESS) { switch (status) {