catch exceptions that may occur, coverity issue 1198845

This commit is contained in:
Dennis Luxen 2014-04-09 11:57:15 -04:00
parent fa615ed9f4
commit 248df9ca2d

View File

@ -54,84 +54,71 @@ std::vector<TurnRestriction> restrictions_vector;
std::vector<NodeID> bollard_node_IDs_vector; std::vector<NodeID> bollard_node_IDs_vector;
std::vector<NodeID> traffic_light_node_IDs_vector; std::vector<NodeID> traffic_light_node_IDs_vector;
int main (int argc, char * argv[]) { int main(int argc, char *argv[])
{
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
if(argc < 3) { if (argc < 3)
SimpleLogger().Write(logWARNING) << {
"usage:\n" << argv[0] << " <osrm> <osrm.restrictions>"; SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0] << " <osrm> <osrm.restrictions>";
return -1; return -1;
} }
SimpleLogger().Write() << try
"Using restrictions from file: " << argv[2]; {
SimpleLogger().Write() << "Using restrictions from file: " << argv[2];
std::ifstream restriction_ifstream(argv[2], std::ios::binary); std::ifstream restriction_ifstream(argv[2], std::ios::binary);
const UUID uuid_orig; const UUID uuid_orig;
UUID uuid_loaded; UUID uuid_loaded;
restriction_ifstream.read((char *)&uuid_loaded, sizeof(UUID)); restriction_ifstream.read((char *)&uuid_loaded, sizeof(UUID));
if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { if (!uuid_loaded.TestGraphUtil(uuid_orig))
SimpleLogger().Write(logWARNING) << {
argv[2] << " was prepared with a different build. " SimpleLogger().Write(logWARNING) << argv[2] << " was prepared with a different build. "
"Reprocess to get rid of this warning."; "Reprocess to get rid of this warning.";
} }
if(!restriction_ifstream.good()) { if (!restriction_ifstream.good())
{
throw OSRMException("Could not access <osrm-restrictions> files"); throw OSRMException("Could not access <osrm-restrictions> files");
} }
uint32_t usable_restriction_count = 0; uint32_t usable_restriction_count = 0;
restriction_ifstream.read( restriction_ifstream.read((char *)&usable_restriction_count, sizeof(uint32_t));
(char*)&usable_restriction_count,
sizeof(uint32_t)
);
restrictions_vector.resize(usable_restriction_count); restrictions_vector.resize(usable_restriction_count);
restriction_ifstream.read( restriction_ifstream.read((char *)&(restrictions_vector[0]),
(char *)&(restrictions_vector[0]), usable_restriction_count * sizeof(TurnRestriction));
usable_restriction_count*sizeof(TurnRestriction)
);
restriction_ifstream.close(); restriction_ifstream.close();
std::ifstream input_stream; std::ifstream input_stream;
input_stream.open(argv[1], std::ifstream::in | std::ifstream::binary); input_stream.open(argv[1], std::ifstream::in | std::ifstream::binary);
if (!input_stream.is_open()) { if (!input_stream.is_open())
{
throw OSRMException("Cannot open osrm file"); throw OSRMException("Cannot open osrm file");
} }
std::vector<ImportEdge> edge_list; std::vector<ImportEdge> edge_list;
NodeID node_based_node_count = readBinaryOSRMGraphFromStream( NodeID node_based_node_count = readBinaryOSRMGraphFromStream(
input_stream, input_stream, edge_list, bollard_node_IDs_vector, traffic_light_node_IDs_vector,
edge_list, &internal_to_external_node_map, restrictions_vector);
bollard_node_IDs_vector,
traffic_light_node_IDs_vector,
&internal_to_external_node_map,
restrictions_vector
);
input_stream.close(); input_stream.close();
BOOST_ASSERT_MSG( BOOST_ASSERT_MSG(restrictions_vector.size() == usable_restriction_count,
restrictions_vector.size() == usable_restriction_count, "size of restrictions_vector changed");
"size of restrictions_vector changed"
);
SimpleLogger().Write() << SimpleLogger().Write() << restrictions_vector.size() << " restrictions, "
restrictions_vector.size() << " restrictions, " << << bollard_node_IDs_vector.size() << " bollard nodes, "
bollard_node_IDs_vector.size() << " bollard nodes, " << << traffic_light_node_IDs_vector.size() << " traffic lights";
traffic_light_node_IDs_vector.size() << " traffic lights";
/*** /***
* Building an edge-expanded graph from node-based input an turn restrictions * Building an edge-expanded graph from node-based input an turn
* restrictions
*/ */
SimpleLogger().Write() << "Starting SCC graph traversal"; SimpleLogger().Write() << "Starting SCC graph traversal";
TarjanSCC * tarjan = new TarjanSCC ( TarjanSCC *tarjan = new TarjanSCC(node_based_node_count, edge_list, bollard_node_IDs_vector,
node_based_node_count, traffic_light_node_IDs_vector, restrictions_vector,
edge_list, internal_to_external_node_map);
bollard_node_IDs_vector,
traffic_light_node_IDs_vector,
restrictions_vector,
internal_to_external_node_map
);
std::vector<ImportEdge>().swap(edge_list); std::vector<ImportEdge>().swap(edge_list);
tarjan->Run(); tarjan->Run();
@ -140,5 +127,10 @@ int main (int argc, char * argv[]) {
std::vector<NodeID>().swap(bollard_node_IDs_vector); std::vector<NodeID>().swap(bollard_node_IDs_vector);
std::vector<NodeID>().swap(traffic_light_node_IDs_vector); std::vector<NodeID>().swap(traffic_light_node_IDs_vector);
SimpleLogger().Write() << "finished component analysis"; SimpleLogger().Write() << "finished component analysis";
}
catch (const std::exception &e)
{
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
}
return 0; return 0;
} }