aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/asmap.cpp2
-rw-r--r--src/util/asmap.h2
-rw-r--r--src/util/check.h8
-rw-r--r--src/util/epochguard.h2
-rw-r--r--src/util/error.cpp2
-rw-r--r--src/util/hasher.h2
-rw-r--r--src/util/macros.h2
-rw-r--r--src/util/message.cpp2
-rw-r--r--src/util/moneystr.cpp2
-rw-r--r--src/util/moneystr.h2
-rw-r--r--src/util/overflow.h31
-rw-r--r--src/util/rbf.h2
-rw-r--r--src/util/readwritefile.h2
-rw-r--r--src/util/settings.cpp2
-rw-r--r--src/util/spanparsing.cpp2
-rw-r--r--src/util/strencodings.cpp18
-rw-r--r--src/util/strencodings.h4
-rw-r--r--src/util/string.h2
-rw-r--r--src/util/syscall_sandbox.cpp2
-rw-r--r--src/util/syscall_sandbox.h2
-rw-r--r--src/util/system.cpp2
-rw-r--r--src/util/system.h2
-rw-r--r--src/util/time.cpp2
-rw-r--r--src/util/time.h2
-rw-r--r--src/util/trace.h2
-rw-r--r--src/util/translation.h2
26 files changed, 67 insertions, 38 deletions
diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp
index b696c65e9d..ffa2755970 100644
--- a/src/util/asmap.cpp
+++ b/src/util/asmap.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020 The Bitcoin Core developers
+// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/asmap.h b/src/util/asmap.h
index 810d70b9a1..844037f816 100644
--- a/src/util/asmap.h
+++ b/src/util/asmap.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020 The Bitcoin Core developers
+// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/check.h b/src/util/check.h
index e60088a2c6..a443c13cf2 100644
--- a/src/util/check.h
+++ b/src/util/check.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020 The Bitcoin Core developers
+// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -33,11 +33,11 @@ class NonFatalCheckError : public std::runtime_error
do { \
if (!(condition)) { \
throw NonFatalCheckError( \
- strprintf("%s:%d (%s)\n" \
- "Internal bug detected: '%s'\n" \
+ strprintf("Internal bug detected: '%s'\n" \
+ "%s:%d (%s)\n" \
"You may report this issue here: %s\n", \
- __FILE__, __LINE__, __func__, \
(#condition), \
+ __FILE__, __LINE__, __func__, \
PACKAGE_BUGREPORT)); \
} \
} while (false)
diff --git a/src/util/epochguard.h b/src/util/epochguard.h
index 3e63e093da..0fec7d2624 100644
--- a/src/util/epochguard.h
+++ b/src/util/epochguard.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/error.cpp b/src/util/error.cpp
index d019ba018d..af8cbd0353 100644
--- a/src/util/error.cpp
+++ b/src/util/error.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2010-2020 The Bitcoin Core developers
+// Copyright (c) 2010-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/hasher.h b/src/util/hasher.h
index 9b79a1b5f1..3d24a4d23c 100644
--- a/src/util/hasher.h
+++ b/src/util/hasher.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2019 The Bitcoin Core developers
+// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/macros.h b/src/util/macros.h
index 0887c80fd7..c9740c8e82 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2019 The Bitcoin Core developers
+// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/message.cpp b/src/util/message.cpp
index 73948e4ff1..2c7f0406f0 100644
--- a/src/util/message.cpp
+++ b/src/util/message.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/moneystr.cpp b/src/util/moneystr.cpp
index 1aed7daacf..2cd7a426f8 100644
--- a/src/util/moneystr.cpp
+++ b/src/util/moneystr.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/moneystr.h b/src/util/moneystr.h
index f37dc1cffd..8180604342 100644
--- a/src/util/moneystr.h
+++ b/src/util/moneystr.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/overflow.h b/src/util/overflow.h
new file mode 100644
index 0000000000..5982af8d04
--- /dev/null
+++ b/src/util/overflow.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2021 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_UTIL_OVERFLOW_H
+#define BITCOIN_UTIL_OVERFLOW_H
+
+#include <limits>
+#include <type_traits>
+
+template <class T>
+[[nodiscard]] bool AdditionOverflow(const T i, const T j) noexcept
+{
+ static_assert(std::is_integral<T>::value, "Integral required.");
+ if (std::numeric_limits<T>::is_signed) {
+ return (i > 0 && j > std::numeric_limits<T>::max() - i) ||
+ (i < 0 && j < std::numeric_limits<T>::min() - i);
+ }
+ return std::numeric_limits<T>::max() - i < j;
+}
+
+template <class T>
+[[nodiscard]] std::optional<T> CheckedAdd(const T i, const T j) noexcept
+{
+ if (AdditionOverflow(i, j)) {
+ return std::nullopt;
+ }
+ return i + j;
+}
+
+#endif // BITCOIN_UTIL_OVERFLOW_H
diff --git a/src/util/rbf.h b/src/util/rbf.h
index aa522d8bfb..a957617389 100644
--- a/src/util/rbf.h
+++ b/src/util/rbf.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2019 The Bitcoin Core developers
+// Copyright (c) 2016-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/readwritefile.h b/src/util/readwritefile.h
index a59d0be131..73437baf1b 100644
--- a/src/util/readwritefile.h
+++ b/src/util/readwritefile.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2015-2020 The Bitcoin Core developers
+// Copyright (c) 2015-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/settings.cpp b/src/util/settings.cpp
index 7fb35c073e..442a55ffb0 100644
--- a/src/util/settings.cpp
+++ b/src/util/settings.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2019 The Bitcoin Core developers
+// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/spanparsing.cpp b/src/util/spanparsing.cpp
index e2e2782bec..50f6aee419 100644
--- a/src/util/spanparsing.cpp
+++ b/src/util/spanparsing.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2018-2019 The Bitcoin Core developers
+// Copyright (c) 2018-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index 430f1963ea..a386f2b7b3 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -92,7 +92,7 @@ std::vector<unsigned char> ParseHex(const char* psz)
signed char c = HexDigit(*psz++);
if (c == (signed char)-1)
break;
- unsigned char n = (c << 4);
+ auto n{uint8_t(c << 4)};
c = HexDigit(*psz++);
if (c == (signed char)-1)
break;
@@ -141,8 +141,7 @@ std::string EncodeBase64(Span<const unsigned char> input)
std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
{
- static const int decode64_table[256] =
- {
+ static const int8_t decode64_table[256]{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
@@ -164,7 +163,7 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
while (*p != 0) {
int x = decode64_table[(unsigned char)*p];
if (x == -1) break;
- val.push_back(x);
+ val.push_back(uint8_t(x));
++p;
}
@@ -220,8 +219,7 @@ std::string EncodeBase32(const std::string& str, bool pad)
std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
{
- static const int decode32_table[256] =
- {
+ static const int8_t decode32_table[256]{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
@@ -243,7 +241,7 @@ std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
while (*p != 0) {
int x = decode32_table[(unsigned char)*p];
if (x == -1) break;
- val.push_back(x);
+ val.push_back(uint8_t(x));
++p;
}
@@ -491,14 +489,14 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
std::string ToLower(const std::string& str)
{
std::string r;
- for (auto ch : str) r += ToLower((unsigned char)ch);
+ for (auto ch : str) r += ToLower(ch);
return r;
}
std::string ToUpper(const std::string& str)
{
std::string r;
- for (auto ch : str) r += ToUpper((unsigned char)ch);
+ for (auto ch : str) r += ToUpper(ch);
return r;
}
diff --git a/src/util/strencodings.h b/src/util/strencodings.h
index 08a5465de1..0945556b5e 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -226,7 +226,7 @@ bool TimingResistantEqual(const T& a, const T& b)
if (b.size() == 0) return a.size() == 0;
size_t accumulator = a.size() ^ b.size();
for (size_t i = 0; i < a.size(); i++)
- accumulator |= a[i] ^ b[i%b.size()];
+ accumulator |= size_t(a[i] ^ b[i%b.size()]);
return accumulator == 0;
}
diff --git a/src/util/string.h b/src/util/string.h
index 07c87cfcda..a3b8df8d78 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020 The Bitcoin Core developers
+// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/syscall_sandbox.cpp b/src/util/syscall_sandbox.cpp
index 6e1cc9b457..3c250b7704 100644
--- a/src/util/syscall_sandbox.cpp
+++ b/src/util/syscall_sandbox.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2020 The Bitcoin Core developers
+// Copyright (c) 2020-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/syscall_sandbox.h b/src/util/syscall_sandbox.h
index 0a0c964f94..f7a1cbdb55 100644
--- a/src/util/syscall_sandbox.h
+++ b/src/util/syscall_sandbox.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2020 The Bitcoin Core developers
+// Copyright (c) 2020-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 99d111b066..8f35b7b6c6 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/system.h b/src/util/system.h
index 37d976221b..a8fd21fcaa 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/time.cpp b/src/util/time.cpp
index eda710b12c..f7712f0dc8 100644
--- a/src/util/time.cpp
+++ b/src/util/time.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/time.h b/src/util/time.h
index 4aee01967d..9d92b23725 100644
--- a/src/util/time.h
+++ b/src/util/time.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2020 The Bitcoin Core developers
+// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/trace.h b/src/util/trace.h
index bb901e05da..7a63f39c83 100644
--- a/src/util/trace.h
+++ b/src/util/trace.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2020 The Bitcoin Core developers
+// Copyright (c) 2020-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/translation.h b/src/util/translation.h
index 62388b568c..aee601d9c1 100644
--- a/src/util/translation.h
+++ b/src/util/translation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020 The Bitcoin Core developers
+// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.