aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2018-05-21 00:20:15 +0200
committerRobin Krahl <me@robin-krahl.de>2018-05-21 00:20:15 +0200
commit5910ec72e0f7abd3f6c876e04a07057b0dd8edaa (patch)
tree9abd26e214e740eb21e58b97c87e780e7aac4cba
parente91e21d5aa6c885fcb0c04ea130c93b72ce9a92b (diff)
downloadlibnitrokey-5910ec72e0f7abd3f6c876e04a07057b0dd8edaa.tar.gz
libnitrokey-5910ec72e0f7abd3f6c876e04a07057b0dd8edaa.tar.bz2
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).
-rw-r--r--NitrokeyManager.cc4
1 files changed, 3 insertions, 1 deletions
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<std::mutex> lock(mex_dev_com_manager);
vector< shared_ptr<Device> > devices = { make_shared<Stick10>(), make_shared<Stick20>() };
+ bool connected = false;
for( auto & d : devices ){
if (d->connect()){
device = std::shared_ptr<Device>(d);
+ connected = true;
}
}
- return device != nullptr;
+ return connected;
}