Skip to content

Commit f2fc03e

Browse files
refactor: use braced init for integer constants instead of c style casts
1 parent 3f8591d commit f2fc03e

23 files changed

+47
-47
lines changed

src/bench/coin_selection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ static CAmount make_hard_case(int utxos, std::vector<OutputGroup>& utxo_pool)
9999
utxo_pool.clear();
100100
CAmount target = 0;
101101
for (int i = 0; i < utxos; ++i) {
102-
target += (CAmount)1 << (utxos+i);
103-
add_coin((CAmount)1 << (utxos+i), 2*i, utxo_pool);
104-
add_coin(((CAmount)1 << (utxos+i)) + ((CAmount)1 << (utxos-1-i)), 2*i + 1, utxo_pool);
102+
target += CAmount{1} << (utxos+i);
103+
add_coin(CAmount{1} << (utxos+i), 2*i, utxo_pool);
104+
add_coin((CAmount{1} << (utxos+i)) + (CAmount{1} << (utxos-1-i)), 2*i + 1, utxo_pool);
105105
}
106106
return target;
107107
}

src/crypto/siphash.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256& val)
119119
SIPROUND;
120120
SIPROUND;
121121
v0 ^= d;
122-
v3 ^= ((uint64_t)4) << 59;
122+
v3 ^= (uint64_t{4}) << 59;
123123
SIPROUND;
124124
SIPROUND;
125-
v0 ^= ((uint64_t)4) << 59;
125+
v0 ^= (uint64_t{4}) << 59;
126126
v2 ^= 0xFF;
127127
SIPROUND;
128128
SIPROUND;
@@ -159,7 +159,7 @@ uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256& val, uint3
159159
SIPROUND;
160160
SIPROUND;
161161
v0 ^= d;
162-
d = (((uint64_t)36) << 56) | extra;
162+
d = ((uint64_t{36}) << 56) | extra;
163163
v3 ^= d;
164164
SIPROUND;
165165
SIPROUND;

src/cuckoocache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class cache
344344
collection_flags.setup(size);
345345
epoch_flags.resize(size);
346346
// Set to 45% as described above
347-
epoch_size = std::max((uint32_t)1, (45 * size) / 100);
347+
epoch_size = std::max(uint32_t{1}, (45 * size) / 100);
348348
// Initially set to wait for a whole epoch
349349
epoch_heuristic_counter = epoch_size;
350350
return size;

src/random.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class FastRandomContext
200200
return rand64() >> (64 - bits);
201201
} else {
202202
if (bitbuf_size < bits) FillBitBuffer();
203-
uint64_t ret = bitbuf & (~(uint64_t)0 >> (64 - bits));
203+
uint64_t ret = bitbuf & (~uint64_t{0} >> (64 - bits));
204204
bitbuf >>= bits;
205205
bitbuf_size -= bits;
206206
return ret;

src/script/interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ class CTransactionSignatureSerializer
13031303
// Serialize the nSequence
13041304
if (nInput != nIn && (fHashSingle || fHashNone))
13051305
// let the others update at will
1306-
::Serialize(s, (int)0);
1306+
::Serialize(s, int{0});
13071307
else
13081308
::Serialize(s, txTo.vin[nInput].nSequence);
13091309
}

src/test/checkqueue_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ static void Correct_Queue_range(std::vector<size_t> range)
194194
BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Zero)
195195
{
196196
std::vector<size_t> range;
197-
range.push_back((size_t)0);
197+
range.push_back(size_t{0});
198198
Correct_Queue_range(range);
199199
}
200200
/** Test that 1 check is correct
201201
*/
202202
BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_One)
203203
{
204204
std::vector<size_t> range;
205-
range.push_back((size_t)1);
205+
range.push_back(size_t{1});
206206
Correct_Queue_range(range);
207207
}
208208
/** Test that MAX check is correct

src/test/crypto_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,14 @@ BOOST_AUTO_TEST_CASE(countbits_tests)
723723
// Check handling of zero.
724724
BOOST_CHECK_EQUAL(CountBits(0), 0U);
725725
} else if (i < 10) {
726-
for (uint64_t j = (uint64_t)1 << (i - 1); (j >> i) == 0; ++j) {
726+
for (uint64_t j = uint64_t{1} << (i - 1); (j >> i) == 0; ++j) {
727727
// Exhaustively test up to 10 bits
728728
BOOST_CHECK_EQUAL(CountBits(j), i);
729729
}
730730
} else {
731731
for (int k = 0; k < 1000; k++) {
732732
// Randomly test 1000 samples of each length above 10 bits.
733-
uint64_t j = ((uint64_t)1) << (i - 1) | ctx.randbits(i - 1);
733+
uint64_t j = (uint64_t{1}) << (i - 1) | ctx.randbits(i - 1);
734734
BOOST_CHECK_EQUAL(CountBits(j), i);
735735
}
736736
}

src/test/fuzz/p2p_transport_serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void initialize_p2p_transport_serialization()
2424
FUZZ_TARGET_INIT(p2p_transport_serialization, initialize_p2p_transport_serialization)
2525
{
2626
// Construct deserializer, with a dummy NodeId
27-
V1TransportDeserializer deserializer{Params(), (NodeId)0, SER_NETWORK, INIT_PROTO_VERSION};
27+
V1TransportDeserializer deserializer{Params(), NodeId{0}, SER_NETWORK, INIT_PROTO_VERSION};
2828
V1TransportSerializer serializer{};
2929
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
3030

src/test/fuzz/versionbits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TestConditionChecker : public AbstractThresholdConditionChecker
5555

5656
bool Condition(int32_t version) const
5757
{
58-
uint32_t mask = ((uint32_t)1) << m_bit;
58+
uint32_t mask = (uint32_t{1}) << m_bit;
5959
return (((version & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && (version & mask) != 0);
6060
}
6161

src/test/merkle_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
5050
// For each of the lower bits in count that are 0, do 1 step. Each
5151
// corresponds to an inner value that existed before processing the
5252
// current leaf, and each needs a hash to combine it.
53-
for (level = 0; !(count & (((uint32_t)1) << level)); level++) {
53+
for (level = 0; !(count & ((uint32_t{1}) << level)); level++) {
5454
if (pbranch) {
5555
if (matchh) {
5656
pbranch->push_back(inner[level]);
@@ -74,12 +74,12 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
7474
int level = 0;
7575
// As long as bit number level in count is zero, skip it. It means there
7676
// is nothing left at this level.
77-
while (!(count & (((uint32_t)1) << level))) {
77+
while (!(count & ((uint32_t{1}) << level))) {
7878
level++;
7979
}
8080
uint256 h = inner[level];
8181
bool matchh = matchlevel == level;
82-
while (count != (((uint32_t)1) << level)) {
82+
while (count != ((uint32_t{1}) << level)) {
8383
// If we reach this point, h is an inner value that is not the top.
8484
// We combine it with itself (Bitcoin's special rule for odd levels in
8585
// the tree) to produce a higher level one.
@@ -89,10 +89,10 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
8989
CHash256().Write(h).Write(h).Finalize(h);
9090
// Increment count to the value it would have if two entries at this
9191
// level had existed.
92-
count += (((uint32_t)1) << level);
92+
count += ((uint32_t{1}) << level);
9393
level++;
9494
// And propagate the result upwards accordingly.
95-
while (!(count & (((uint32_t)1) << level))) {
95+
while (!(count & ((uint32_t{1}) << level))) {
9696
if (pbranch) {
9797
if (matchh) {
9898
pbranch->push_back(inner[level]);

0 commit comments

Comments
 (0)