aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-12-15 10:59:11 +0100
committerMarcoFalke <falke.marco@gmail.com>2021-12-15 10:59:28 +0100
commit7006496a5c03524a7295c70f66ceb8d15fee2919 (patch)
treee69568df0c1cd6f32c0c1b626db3b70627e1b694 /src
parent40fdb9ece979622478fcda989c14dfb7536c4c8c (diff)
parentfa5865a9e339e7fe4068fbcce2ac055ed49eddfd (diff)
downloadbitcoin-7006496a5c03524a7295c70f66ceb8d15fee2919.tar.xz
Merge bitcoin/bitcoin#23756: refactor: Fix implicit integer sign changes in strencodings
fa5865a9e339e7fe4068fbcce2ac055ed49eddfd Reduce size of strencodings decode tables (MarcoFalke) fad6761cf7875c7e91fd76398a71a9f9c6b3ea82 Fix implicit integer sign changes in strencodings (MarcoFalke) Pull request description: This removes casts where they are nonsensical (ToUpper/ToLower) and adds them where needed. Then, remove the suppressions. Also, reduce static memory usage. ACKs for top commit: shaavan: crACK fa5865a9e339e7fe4068fbcce2ac055ed49eddfd Tree-SHA512: 29850fb616789befad17f71731f322b2238e94ec431cda293629de540f7ab02060a9fc5b7666168ca2592048df5a39a2975177f47771d4d8211d90321052549d
Diffstat (limited to 'src')
-rw-r--r--src/util/strencodings.cpp16
-rw-r--r--src/util/strencodings.h2
2 files changed, 8 insertions, 10 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index 430f1963ea..f4768d5bb6 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -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..5813e8d212 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -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;
}