BEAM without particles specified crashes
Summary
When the BEAM command has no particles (NPARTS) specified, OPAL crashes.
Steps to reproduce
What is the current bug behavior?
Crash.
What is the expected correct behavior?
Exit with error that no particles are specified.
Relevant logs and/or screenshots
traceback:
Program received signal SIGSEGV, Segmentation fault.
Distribution::createOpalT(PartBunchBase<double, 3u>*, unsigned long&) ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/Distribution/Distribution.cpp:2820
2820 double maxTOrZ = *longIt;
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.212.el6.x86_64 infinipath-psm-3.0.1-115.1015_open.2.el6.x86_64 libnl-1.1.4-2.el6.x86_64 nss-pam-ldapd-0.7.5-20.el6_6.3.x86_64 zlib-1.2.3-29.el6.x86_64
(gdb) bt
#0 Distribution::createOpalT(PartBunchBase<double, 3u>*, unsigned long&) ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/Distribution/Distribution.cpp:2820
#1 0x0000000000885814 in TrackRun::setDistributionParallelT(Beam*) ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/Classic/Algorithms/PartBunchBase.hpp:254
#2 0x000000000088861f in TrackRun::setupTTracker() () at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/Track/TrackRun.cpp:505
#3 0x000000000088914c in TrackRun::execute() () at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/Track/TrackRun.cpp:197
#4 0x00000000006ea0aa in OpalParser::execute(Object*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const () at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:139
#5 0x00000000006ee452 in OpalParser::parseAction(Statement&) const ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:172
#6 0x00000000006edcf3 in OpalParser::parse(Statement&) const ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:90
#7 0x00000000006e9d4c in OpalParser::run() const ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:607
#8 0x000000000088276a in TrackCmd::execute() () at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/Track/TrackCmd.cpp:212
#9 0x00000000006ea0aa in OpalParser::execute(Object*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const () at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:139
#10 0x00000000006ee452 in OpalParser::parseAction(Statement&) const ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:172
#11 0x00000000006edcf3 in OpalParser::parse(Statement&) const ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:90
#12 0x00000000006e9d4c in OpalParser::run() const ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:607
#13 0x00000000006eeb90 in OpalParser::run(TokenStream*) const ()
at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/OpalParser/OpalParser.cpp:632
#14 0x0000000000642812 in main () at /home/scratch/OPAL/OPAL-fork/OPAL-src/src/Main.cpp:360
Possible fixes
The method that crashes, takes the first entry without checking its size: https://gitlab.psi.ch/OPAL/src/blob/master/src/Distribution/Distribution.cpp#L2817
double Distribution::getMaxTOrZ() {
std::vector<double>::iterator longIt = tOrZDist_m.begin();
double maxTOrZ = *longIt;
This should be fixed. But in addition, it would be good to catch this when parsing, and OPAL can exit with an exception.