Skip to content

Commit

Permalink
Add exception handling for options parse
Browse files Browse the repository at this point in the history
To avoid core dump, add exception handling for
program options parsing.

Signed-off-by: Yadong Qi <[email protected]>
  • Loading branch information
YadongQi authored and sysopenci committed Mar 16, 2023
1 parent ff955e0 commit f232944
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/vm_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,13 @@ class CivOptions final {
CivOptions& operator=(const CivOptions &) = delete;

bool ParseOptions(int argc, char* argv[]) {
po::store(po::command_line_parser(argc, argv).options(cmdline_options_).run(), vm_);
po::notify(vm_);
try {
po::store(po::command_line_parser(argc, argv).options(cmdline_options_).run(), vm_);
po::notify(vm_);
} catch (std::exception& e) {
std::cout << e.what() << "\n";
return false;
}

if (vm_.empty()) {
PrintHelp();
Expand Down

0 comments on commit f232944

Please sign in to comment.