summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/auth.cpp2
-rw-r--r--src/util/base64.cpp5
-rw-r--r--src/util/container.h21
-rw-r--r--src/util/numeric.cpp2
-rw-r--r--src/util/pointedthing.h2
-rw-r--r--src/util/serialize.cpp20
-rw-r--r--src/util/serialize.h2
-rw-r--r--src/util/sha1.cpp14
-rw-r--r--src/util/srp.cpp9
-rw-r--r--src/util/thread.h6
10 files changed, 44 insertions, 39 deletions
diff --git a/src/util/auth.cpp b/src/util/auth.cpp
index c329e36e6..3dd5a9afa 100644
--- a/src/util/auth.cpp
+++ b/src/util/auth.cpp
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "base64.h"
#include "sha1.h"
#include "srp.h"
-#include "string.h"
+#include "util/string.h"
#include "debug.h"
// Get an sha-1 hash of the player's name combined with
diff --git a/src/util/base64.cpp b/src/util/base64.cpp
index e14de7de2..c75f98598 100644
--- a/src/util/base64.cpp
+++ b/src/util/base64.cpp
@@ -40,8 +40,9 @@ static inline bool is_base64(unsigned char c) {
bool base64_is_valid(std::string const& s)
{
- for(size_t i=0; i<s.size(); i++)
- if(!is_base64(s[i])) return false;
+ for (char i : s)
+ if (!is_base64(i))
+ return false;
return true;
}
diff --git a/src/util/container.h b/src/util/container.h
index af85d80e3..81f085017 100644
--- a/src/util/container.h
+++ b/src/util/container.h
@@ -79,7 +79,7 @@ template<typename Key, typename Value>
class MutexedMap
{
public:
- MutexedMap() {}
+ MutexedMap() = default;
void set(const Key &name, const Value &value)
{
@@ -128,7 +128,8 @@ public:
template<typename Key, typename U, typename Caller, typename CallerData>
friend class RequestQueue;
- MutexedQueue() {}
+ MutexedQueue() = default;
+
bool empty() const
{
MutexAutoLock lock(m_mutex);
@@ -153,9 +154,9 @@ public:
T t = m_queue.front();
m_queue.pop_front();
return t;
- } else {
- return T();
}
+
+ return T();
}
T pop_front(u32 wait_time_max_ms)
@@ -166,9 +167,9 @@ public:
T t = m_queue.front();
m_queue.pop_front();
return t;
- } else {
- throw ItemNotFoundException("MutexedQueue: queue is empty");
}
+
+ throw ItemNotFoundException("MutexedQueue: queue is empty");
}
T pop_frontNoEx()
@@ -190,9 +191,9 @@ public:
T t = m_queue.back();
m_queue.pop_back();
return t;
- } else {
- throw ItemNotFoundException("MutexedQueue: queue is empty");
}
+
+ throw ItemNotFoundException("MutexedQueue: queue is empty");
}
/* this version of pop_back returns a empty element of T on timeout.
@@ -206,9 +207,9 @@ public:
T t = m_queue.back();
m_queue.pop_back();
return t;
- } else {
- return T();
}
+
+ return T();
}
T pop_backNoEx()
diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp
index e6a9cb75e..a48a72a8a 100644
--- a/src/util/numeric.cpp
+++ b/src/util/numeric.cpp
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "../constants.h" // BS, MAP_BLOCKSIZE
#include "../noise.h" // PseudoRandom, PcgRandom
#include "../threading/mutex_auto_lock.h"
-#include <string.h>
+#include <cstring>
// myrand
diff --git a/src/util/pointedthing.h b/src/util/pointedthing.h
index c13436fcd..bd95ef1f3 100644
--- a/src/util/pointedthing.h
+++ b/src/util/pointedthing.h
@@ -81,7 +81,7 @@ struct PointedThing
f32 distanceSq = 0;
//! Constructor for POINTEDTHING_NOTHING
- PointedThing() {};
+ PointedThing() = default;
//! Constructor for POINTEDTHING_NODE
PointedThing(const v3s16 &under, const v3s16 &above,
const v3s16 &real_under, const v3f &point, const v3s16 &normal,
diff --git a/src/util/serialize.cpp b/src/util/serialize.cpp
index 75843cb1b..49db9cf85 100644
--- a/src/util/serialize.cpp
+++ b/src/util/serialize.cpp
@@ -156,8 +156,8 @@ std::string serializeWideString(const std::wstring &plain)
writeU16((u8 *)buf, plain.size());
s.append(buf, 2);
- for (u32 i = 0; i < plain.size(); i++) {
- writeU16((u8 *)buf, plain[i]);
+ for (wchar_t i : plain) {
+ writeU16((u8 *)buf, i);
s.append(buf, 2);
}
return s;
@@ -246,8 +246,7 @@ std::string serializeJsonString(const std::string &plain)
std::ostringstream os(std::ios::binary);
os << "\"";
- for (size_t i = 0; i < plain.size(); i++) {
- char c = plain[i];
+ for (char c : plain) {
switch (c) {
case '"':
os << "\\\"";
@@ -308,7 +307,9 @@ std::string deSerializeJsonString(std::istream &is)
if (c == '"') {
return os.str();
- } else if (c == '\\') {
+ }
+
+ if (c == '\\') {
c2 = is.get();
if (is.eof())
throw SerializationError("JSON string ended prematurely");
@@ -390,17 +391,18 @@ std::string deSerializeJsonStringIfNeeded(std::istream &is)
// Found end of word
is.unget();
break;
- } else {
- tmp_os << c;
}
+
+ tmp_os << c;
}
expect_initial_quote = false;
}
if (is_json) {
std::istringstream tmp_is(tmp_os.str(), std::ios::binary);
return deSerializeJsonString(tmp_is);
- } else
- return tmp_os.str();
+ }
+
+ return tmp_os.str();
}
////
diff --git a/src/util/serialize.h b/src/util/serialize.h
index 0607ff37a..0a1c96205 100644
--- a/src/util/serialize.h
+++ b/src/util/serialize.h
@@ -37,7 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <endian.h>
#endif
#endif
-#include <string.h> // for memcpy
+#include <cstring> // for memcpy
#include <iostream>
#include <string>
#include <vector>
diff --git a/src/util/sha1.cpp b/src/util/sha1.cpp
index c04b6c0c0..d61b262af 100644
--- a/src/util/sha1.cpp
+++ b/src/util/sha1.cpp
@@ -24,10 +24,10 @@ SOFTWARE.
*/
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
+#include <cstdio>
+#include <cstring>
+#include <cstdlib>
+#include <cassert>
#include "sha1.h"
@@ -96,7 +96,7 @@ void SHA1::process()
+(bytes[t*4 + 2] << 8)
+ bytes[t*4 + 3];
for(; t< 80; t++ ) W[t] = lrot( W[t-3]^W[t-8]^W[t-14]^W[t-16], 1 );
-
+
/* main loop */
Uint32 temp;
for( t = 0; t < 80; t++ )
@@ -154,7 +154,7 @@ void SHA1::addBytes( const char* data, int num )
num -= toCopy;
data += toCopy;
unprocessedBytes += toCopy;
-
+
// there is a full block
if( unprocessedBytes == 64 ) process();
}
@@ -168,7 +168,7 @@ unsigned char* SHA1::getDigest()
Uint32 totalBitsH = size >> 29;
// add 0x80 to the message
addBytes( "\x80", 1 );
-
+
unsigned char footer[64] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
diff --git a/src/util/srp.cpp b/src/util/srp.cpp
index e0ddb9020..aa8dcb4a7 100644
--- a/src/util/srp.cpp
+++ b/src/util/srp.cpp
@@ -31,13 +31,14 @@
#include <windows.h>
#include <wincrypt.h>
#else
- #include <time.h>
+ #include <ctime>
+
#endif
// clang-format on
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
+#include <cstdlib>
+#include <cstring>
+#include <cstdio>
#include <config.h>
diff --git a/src/util/thread.h b/src/util/thread.h
index fbd04c08e..52c6c6aba 100644
--- a/src/util/thread.h
+++ b/src/util/thread.h
@@ -78,8 +78,8 @@ public:
template<typename Key, typename T, typename Caller, typename CallerData>
class GetRequest {
public:
- GetRequest() {}
- ~GetRequest() {}
+ GetRequest() = default;
+ ~GetRequest() = default;
GetRequest(const Key &a_key): key(a_key)
{
@@ -189,7 +189,7 @@ class UpdateThread : public Thread
{
public:
UpdateThread(const std::string &name) : Thread(name + "Update") {}
- ~UpdateThread() {}
+ ~UpdateThread() = default;
void deferUpdate() { m_update_sem.post(); }