Skip to content
Snippets Groups Projects
Commit b28fdf12 authored by Dan Guest's avatar Dan Guest
Browse files

Fix segfault when ttree2hdf5 runs on empty files

When ttree2hdf5 was passed and empty file would segfault. This commit
adds some protection against that situation. I also added a thin
wrapper on the `main(...)` function to catch logic errors and make the
error handling slightly cleaner.


Former-commit-id: 7bff2a1bb32a01992738e5d709136c21c9989535
parent dc92798f
No related merge requests found
......@@ -43,6 +43,9 @@ namespace H5Utils {
}
std::set<std::string> keys;
int n_keys = file->GetListOfKeys()->GetSize();
if (n_keys == 0) {
throw std::logic_error("no keys found in file");
}
for (int keyn = 0; keyn < n_keys; keyn++) {
keys.insert(file->GetListOfKeys()->At(keyn)->GetName());
}
......
......@@ -14,7 +14,18 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
#include <iostream>
#include <memory>
int run(int argc, char* argv[]);
int main(int argc, char* argv[]) {
try {
return run(argc, argv);
} catch (std::logic_error& e) {
std::cerr << "ERROR: " << e.what() << ", quitting." << std::endl;
return 1;
}
}
int run(int argc, char* argv[]) {
using namespace H5Utils;
AppOpts opts = getTreeCopyOpts(argc, argv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment