From 5910ec72e0f7abd3f6c876e04a07057b0dd8edaa Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 21 May 2018 00:20:15 +0200 Subject: Correct return value for NitrokeyManager::connect() NitrokeyManager::connect() currently returns true if the device pointer is set. Yet this does not mean that the connection was successful. For example, NitrokeyManger::connect(const char*) sets the device pointer even if it was not successful. This patch introduces a variable that keeps track of the connection instead of checking the device pointer. This corrects the return value without changing the behavior of the connect method (returning the Storage device if both a Pro and a Storage device are present). --- NitrokeyManager.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 085bf78..f86a3eb 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -234,12 +234,14 @@ using nitrokey::misc::strcpyT; bool NitrokeyManager::connect() { std::lock_guard lock(mex_dev_com_manager); vector< shared_ptr > devices = { make_shared(), make_shared() }; + bool connected = false; for( auto & d : devices ){ if (d->connect()){ device = std::shared_ptr(d); + connected = true; } } - return device != nullptr; + return connected; } -- cgit v1.2.1