Skip to content

Commit fad6761

Browse files
author
MarcoFalke
committed
Fix implicit integer sign changes in strencodings
1 parent eb63b8f commit fad6761

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/util/strencodings.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ std::vector<unsigned char> ParseHex(const char* psz)
9292
signed char c = HexDigit(*psz++);
9393
if (c == (signed char)-1)
9494
break;
95-
unsigned char n = (c << 4);
95+
auto n{uint8_t(c << 4)};
9696
c = HexDigit(*psz++);
9797
if (c == (signed char)-1)
9898
break;
@@ -164,7 +164,7 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
164164
while (*p != 0) {
165165
int x = decode64_table[(unsigned char)*p];
166166
if (x == -1) break;
167-
val.push_back(x);
167+
val.push_back(uint8_t(x));
168168
++p;
169169
}
170170

@@ -243,7 +243,7 @@ std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
243243
while (*p != 0) {
244244
int x = decode32_table[(unsigned char)*p];
245245
if (x == -1) break;
246-
val.push_back(x);
246+
val.push_back(uint8_t(x));
247247
++p;
248248
}
249249

@@ -491,14 +491,14 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
491491
std::string ToLower(const std::string& str)
492492
{
493493
std::string r;
494-
for (auto ch : str) r += ToLower((unsigned char)ch);
494+
for (auto ch : str) r += ToLower(ch);
495495
return r;
496496
}
497497

498498
std::string ToUpper(const std::string& str)
499499
{
500500
std::string r;
501-
for (auto ch : str) r += ToUpper((unsigned char)ch);
501+
for (auto ch : str) r += ToUpper(ch);
502502
return r;
503503
}
504504

src/util/strencodings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ bool TimingResistantEqual(const T& a, const T& b)
226226
if (b.size() == 0) return a.size() == 0;
227227
size_t accumulator = a.size() ^ b.size();
228228
for (size_t i = 0; i < a.size(); i++)
229-
accumulator |= a[i] ^ b[i%b.size()];
229+
accumulator |= size_t(a[i] ^ b[i%b.size()]);
230230
return accumulator == 0;
231231
}
232232

test/sanitizer_suppressions/ubsan

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ implicit-integer-sign-change:test/skiplist_tests.cpp
7676
implicit-integer-sign-change:test/streams_tests.cpp
7777
implicit-integer-sign-change:test/transaction_tests.cpp
7878
implicit-integer-sign-change:txmempool.cpp
79-
implicit-integer-sign-change:util/strencodings.cpp
80-
implicit-integer-sign-change:util/strencodings.h
8179
implicit-integer-sign-change:validation.cpp
8280
implicit-integer-sign-change:zmq/zmqpublishnotifier.cpp
8381
implicit-signed-integer-truncation,implicit-integer-sign-change:chain.h

0 commit comments

Comments
 (0)