From 00bada6fb9693f2b3ef4002b4886f7fb9e89860b Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 5 Feb 2015 02:47:35 +0300 Subject: [PATCH] Coverity CID 1203388..1203395 --- libuavcan_drivers/linux/apps/test_node.cpp | 32 +++++++++------ libuavcan_drivers/linux/apps/test_socket.cpp | 40 +++++++++++-------- .../linux/apps/test_time_sync.cpp | 30 +++++++++----- 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/libuavcan_drivers/linux/apps/test_node.cpp b/libuavcan_drivers/linux/apps/test_node.cpp index cb00a98c99..3ec9b0938b 100644 --- a/libuavcan_drivers/linux/apps/test_node.cpp +++ b/libuavcan_drivers/linux/apps/test_node.cpp @@ -102,19 +102,27 @@ static void runForever(const uavcan_linux::NodePtr& node) int main(int argc, const char** argv) { - if (argc < 3) + try { - std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + if (argc < 3) + { + std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + return 1; + } + const int self_node_id = std::stoi(argv[1]); + std::vector iface_names; + for (int i = 2; i < argc; i++) + { + iface_names.emplace_back(argv[i]); + } + uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node"); + std::cout << "Node initialized successfully" << std::endl; + runForever(node); + return 0; + } + catch (const std::exception& ex) + { + std::cerr << "Exception: " << ex.what() << std::endl; return 1; } - const int self_node_id = std::stoi(argv[1]); - std::vector iface_names; - for (int i = 2; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node"); - std::cout << "Node initialized successfully" << std::endl; - runForever(node); - return 0; } diff --git a/libuavcan_drivers/linux/apps/test_socket.cpp b/libuavcan_drivers/linux/apps/test_socket.cpp index 5c8a33e2ce..1b37fc8c7a 100644 --- a/libuavcan_drivers/linux/apps/test_socket.cpp +++ b/libuavcan_drivers/linux/apps/test_socket.cpp @@ -332,23 +332,31 @@ static void testDriver(const std::vector& iface_names) int main(int argc, const char** argv) { - if (argc < 2) + try { - std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + if (argc < 2) + { + std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + return 1; + } + + std::vector iface_names; + for (int i = 1; i < argc; i++) + { + iface_names.emplace_back(argv[i]); + } + + testNonexistentIface(); + testSocketRxTx(iface_names[0]); + testSocketFilters(iface_names[0]); + + testDriver(iface_names); + + return 0; + } + catch (const std::exception& ex) + { + std::cerr << "Exception: " << ex.what() << std::endl; return 1; } - - std::vector iface_names; - for (int i = 1; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - - testNonexistentIface(); - testSocketRxTx(iface_names[0]); - testSocketFilters(iface_names[0]); - - testDriver(iface_names); - - return 0; } diff --git a/libuavcan_drivers/linux/apps/test_time_sync.cpp b/libuavcan_drivers/linux/apps/test_time_sync.cpp index 8da3e2ad1b..b85f889b48 100644 --- a/libuavcan_drivers/linux/apps/test_time_sync.cpp +++ b/libuavcan_drivers/linux/apps/test_time_sync.cpp @@ -84,18 +84,26 @@ static void runForever(const uavcan_linux::NodePtr& node) int main(int argc, const char** argv) { - if (argc < 3) + try { - std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + if (argc < 3) + { + std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + return 1; + } + const int self_node_id = std::stoi(argv[1]); + std::vector iface_names; + for (int i = 2; i < argc; i++) + { + iface_names.emplace_back(argv[i]); + } + uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node_status_monitor"); + runForever(node); + return 0; + } + catch (const std::exception& ex) + { + std::cerr << "Exception: " << ex.what() << std::endl; return 1; } - const int self_node_id = std::stoi(argv[1]); - std::vector iface_names; - for (int i = 2; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node_status_monitor"); - runForever(node); - return 0; }