diff --git a/src/musrfit.cpp b/src/musrfit.cpp index 654c88af9..f83f8ecba 100644 --- a/src/musrfit.cpp +++ b/src/musrfit.cpp @@ -518,6 +518,7 @@ int main(int argc, char *argv[]) } } + memset(filename, '\0', sizeof(filename)); strcpy(filename, ""); for (int i=1; i> musrfit **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data(); std::cerr << std::endl; } else { - strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data()); + memset(startup_path_name, '\0', sizeof(startup_path_name)); + strncpy(startup_path_name, startupHandler->GetStartupFilePath().Data(), sizeof(startup_path_name)); saxParser->ConnectToHandler("PStartupHandler", startupHandler.get()); //status = saxParser->ParseFile(startup_path_name); // parsing the file as above seems to lead to problems in certain environments; @@ -696,15 +698,35 @@ int main(int argc, char *argv[]) bool success = dataHandler->IsAllDataAvailable(); if (!success) { - std::cout << std::endl << ">> musrfit **ERROR** Couldn't read all data files, will quit ..." << std::endl; + std::cerr << std::endl << ">> musrfit **ERROR** Couldn't read all data files, will quit ..." << std::endl; } // if present, replace the run title of the with the run title of the FIRST run in the run block of the msr-file if (title_from_data_file && success) { PMsrRunList *rl = msrHandler->GetMsrRunList(); - PRawRunData *rrd = dataHandler->GetRunData(*(rl->at(0).GetRunName())); - if (rrd->GetRunTitle()->Length() > 0) - msrHandler->SetMsrTitle(*rrd->GetRunTitle()); + if (rl->empty()) { + success = false; + std::cerr << std::endl << ">> musrfit **ERROR** no run list present." << std::endl; + } + if (success) { + TString *name = rl->at(0).GetRunName(); + if (name == nullptr) { + std::cerr << std::endl << ">> musrfit **ERROR** to obtain run list name." << std::endl; + success = false; + } + PRawRunData *rrd = nullptr; + if (success) { + rrd = dataHandler->GetRunData(*(rl->at(0).GetRunName())); + if (rrd == nullptr) { + std::cerr << std::endl << ">> musrfit **ERROR** no raw run data avaliable." << std::endl; + success = false; + } + } + if (success) { + if (rrd->GetRunTitle()->Length() > 0) + msrHandler->SetMsrTitle(*rrd->GetRunTitle()); + } + } } // generate the necessary fit histogramms for the fit @@ -725,7 +747,7 @@ int main(int argc, char *argv[]) // start timeout thread std::unique_ptr th; if (timeout_enabled) { - pid_t musrfit_pid = getpid(); + static pid_t musrfit_pid = getpid(); th = std::make_unique(musrfit_timeout, (void*)&musrfit_pid); if (th) { th->Run(); @@ -813,6 +835,10 @@ int main(int argc, char *argv[]) } } + if (th && timeout_enabled) { + th->Kill(); + } + std::cout << std::endl << "done ..." << std::endl; return PMUSR_SUCCESS;