diff --git a/main.cpp b/main.cpp index de9c531..e61c425 100644 --- a/main.cpp +++ b/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include // POSIX #include @@ -130,10 +131,10 @@ int main(int argc, const char * argv[]) { throw std::runtime_error("unrecognized option"); } } + std::vector names {sc::plugin::names()}; if (optind == argc) { // here when no file args if (random_saver) { - std::vector names {sc::plugin::names()}; saver_name = sc::random::choice(names); } else { saver_name = "Default"; @@ -146,6 +147,11 @@ int main(int argc, const char * argv[]) { if (random_saver) { std::cerr << "screensaver: warning: -r option overridden by file arg\n"; } + auto it = std::find(names.begin(), names.end(), saver_name); + if (it == names.end()) { + saver_name = ""; + throw std::out_of_range(saver_name); + } break; // only first one used } catch (const std::runtime_error& ex) { std::cerr << "screensaver: " << ex.what() << '\n';