aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2024-04-19 23:39:47 +0200
committerPierre Ossman <ossman@cendio.se>2024-06-24 13:50:11 +0200
commitc959b5280a99570b2c0698ba6c89fba7354edda9 (patch)
tree31a41aec82fcce1dc5da264193ae1470dbf2c735 /common
parent8233030ad87f6cfa4d058f60e8ab306c54d38798 (diff)
downloadtigervnc-c959b5280a99570b2c0698ba6c89fba7354edda9.tar.gz
tigervnc-c959b5280a99570b2c0698ba6c89fba7354edda9.zip
Prefer std::find() over manual search
Let's avoid reimplementing something basic that's available in the standard library. It also makes the code easier to read.
Diffstat (limited to 'common')
-rw-r--r--common/rfb/CConnection.cxx24
-rw-r--r--common/rfb/CSecurityVeNCrypt.cxx19
-rw-r--r--common/rfb/SConnection.cxx9
-rw-r--r--common/rfb/Security.cxx18
-rw-r--r--common/rfb/Timer.cxx10
5 files changed, 33 insertions, 47 deletions
diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx
index 2d1c20b6..212671aa 100644
--- a/common/rfb/CConnection.cxx
+++ b/common/rfb/CConnection.cxx
@@ -25,6 +25,8 @@
#include <stdio.h>
#include <string.h>
+#include <algorithm>
+
#include <rfb/Exception.h>
#include <rfb/clipboardTypes.h>
#include <rfb/fenceTypes.h>
@@ -226,14 +228,8 @@ bool CConnection::processSecurityTypesMsg()
state_ = RFBSTATE_SECURITY_REASON;
return true;
} else if (secType == secTypeNone || secType == secTypeVncAuth) {
- std::list<uint8_t>::iterator i;
- for (i = secTypes.begin(); i != secTypes.end(); i++)
- if (*i == secType) {
- secType = *i;
- break;
- }
-
- if (i == secTypes.end())
+ if (std::find(secTypes.begin(), secTypes.end(),
+ secType) == secTypes.end())
secType = secTypeInvalid;
} else {
vlog.error("Unknown 3.3 security type %d", secType);
@@ -260,8 +256,6 @@ bool CConnection::processSecurityTypesMsg()
return true;
}
- std::list<uint8_t>::iterator j;
-
for (int i = 0; i < nServerSecTypes; i++) {
uint8_t serverSecType = is->readU8();
vlog.debug("Server offers security type %s(%d)",
@@ -272,12 +266,10 @@ bool CConnection::processSecurityTypesMsg()
* It means server's order specifies priority.
*/
if (secType == secTypeInvalid) {
- for (j = secTypes.begin(); j != secTypes.end(); j++)
- if (*j == serverSecType) {
- secType = *j;
- break;
- }
- }
+ if (std::find(secTypes.begin(), secTypes.end(),
+ serverSecType) != secTypes.end())
+ secType = serverSecType;
+ }
}
// Inform the server of our decision
diff --git a/common/rfb/CSecurityVeNCrypt.cxx b/common/rfb/CSecurityVeNCrypt.cxx
index ef149c43..2b74fe29 100644
--- a/common/rfb/CSecurityVeNCrypt.cxx
+++ b/common/rfb/CSecurityVeNCrypt.cxx
@@ -26,13 +26,15 @@
#include <config.h>
#endif
+#include <algorithm>
+#include <list>
+
#include <rfb/Exception.h>
#include <rdr/InStream.h>
#include <rdr/OutStream.h>
#include <rfb/CConnection.h>
#include <rfb/CSecurityVeNCrypt.h>
#include <rfb/LogWriter.h>
-#include <list>
using namespace rfb;
using namespace rdr;
@@ -156,22 +158,17 @@ bool CSecurityVeNCrypt::processMsg()
if (!haveChosenType) {
chosenType = secTypeInvalid;
uint8_t i;
- list<uint32_t>::iterator j;
list<uint32_t> secTypes;
secTypes = security->GetEnabledExtSecTypes();
/* Honor server's security type order */
for (i = 0; i < nAvailableTypes; i++) {
- for (j = secTypes.begin(); j != secTypes.end(); j++) {
- if (*j == availableTypes[i]) {
- chosenType = *j;
- break;
- }
- }
-
- if (chosenType != secTypeInvalid)
- break;
+ if (std::find(secTypes.begin(), secTypes.end(),
+ availableTypes[i]) != secTypes.end()) {
+ chosenType = availableTypes[i];
+ break;
+ }
}
/* Set up the stack according to the chosen type: */
diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx
index 8f109a06..98fa730b 100644
--- a/common/rfb/SConnection.cxx
+++ b/common/rfb/SConnection.cxx
@@ -23,6 +23,9 @@
#include <stdio.h>
#include <string.h>
+
+#include <algorithm>
+
#include <rfb/Exception.h>
#include <rfb/Security.h>
#include <rfb/clipboardTypes.h>
@@ -206,12 +209,10 @@ void SConnection::processSecurityType(int secType)
{
// Verify that the requested security type should be offered
std::list<uint8_t> secTypes;
- std::list<uint8_t>::iterator i;
secTypes = security.GetEnabledSecTypes();
- for (i=secTypes.begin(); i!=secTypes.end(); i++)
- if (*i == secType) break;
- if (i == secTypes.end())
+ if (std::find(secTypes.begin(), secTypes.end(),
+ secType) == secTypes.end())
throw Exception("Requested security type not available");
vlog.info("Client requests security type %s(%d)",
diff --git a/common/rfb/Security.cxx b/common/rfb/Security.cxx
index 34396b0c..55f766a1 100644
--- a/common/rfb/Security.cxx
+++ b/common/rfb/Security.cxx
@@ -23,6 +23,8 @@
#include <string.h>
+#include <algorithm>
+
#include <rfb/LogWriter.h>
#include <rfb/Security.h>
#include <rfb/util.h>
@@ -85,22 +87,18 @@ const std::list<uint32_t> Security::GetEnabledExtSecTypes(void)
void Security::EnableSecType(uint32_t secType)
{
- list<uint32_t>::iterator i;
-
- for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++)
- if (*i == secType)
- return;
+ if (std::find(enabledSecTypes.begin(), enabledSecTypes.end(),
+ secType) != enabledSecTypes.end())
+ return;
enabledSecTypes.push_back(secType);
}
bool Security::IsSupported(uint32_t secType)
{
- list<uint32_t>::iterator i;
-
- for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++)
- if (*i == secType)
- return true;
+ if (std::find(enabledSecTypes.begin(), enabledSecTypes.end(),
+ secType) != enabledSecTypes.end())
+ return true;
if (secType == secTypeVeNCrypt)
return true;
diff --git a/common/rfb/Timer.cxx b/common/rfb/Timer.cxx
index b695df86..5216c7e3 100644
--- a/common/rfb/Timer.cxx
+++ b/common/rfb/Timer.cxx
@@ -26,6 +26,8 @@
#include <stdio.h>
#include <sys/time.h>
+#include <algorithm>
+
#include <rfb/Timer.h>
#include <rfb/util.h>
#include <rfb/LogWriter.h>
@@ -153,12 +155,8 @@ void Timer::stop() {
}
bool Timer::isStarted() {
- std::list<Timer*>::iterator i;
- for (i=pending.begin(); i!=pending.end(); i++) {
- if (*i == this)
- return true;
- }
- return false;
+ return std::find(pending.begin(), pending.end(),
+ this) != pending.end();
}
int Timer::getTimeoutMs() {