Skip to content

Commit 01129ca

Browse files
committed
Merge bitcoin/bitcoin#23214: Replace stoul with ToIntegral in dbwrapper
fa165e9 Replace stoul with ToIntegral in dbwrapper (MarcoFalke) Pull request description: The string is created with `%llu`. See: https://github.com/bitcoin/bitcoin/blob/7fcf53f7b4524572d1d0c9a5fdc388e87eb02416/src/leveldb/db/db_impl.cc#L1436-L1437 So it seems odd to silently accept when parsing: whitespace, a sign character, trailing chars, overflow, .... Fix that by using the stricter ToIntegral. ACKs for top commit: laanwj: Code review ACK fa165e9 practicalswift: cr ACK fa165e9 theStack: Code-review ACK fa165e9 Tree-SHA512: b87f01431ca0b971ff84610022da8679d3c33470b88cfc3f4a337e6e176a0455715588aefd40e8e2bbe7459d902dc89d7bfe34e7fd66755f631cc18dc039fa2f
2 parents d1e63aa + fa165e9 commit 01129ca

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/dbwrapper.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,15 @@ bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
197197
return true;
198198
}
199199

200-
size_t CDBWrapper::DynamicMemoryUsage() const {
200+
size_t CDBWrapper::DynamicMemoryUsage() const
201+
{
201202
std::string memory;
202-
if (!pdb->GetProperty("leveldb.approximate-memory-usage", &memory)) {
203+
std::optional<size_t> parsed;
204+
if (!pdb->GetProperty("leveldb.approximate-memory-usage", &memory) || !(parsed = ToIntegral<size_t>(memory))) {
203205
LogPrint(BCLog::LEVELDB, "Failed to get approximate-memory-usage property\n");
204206
return 0;
205207
}
206-
return stoul(memory);
208+
return parsed.value();
207209
}
208210

209211
// Prefixed with null character to avoid collisions with other keys

test/lint/lint-locale-dependence.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export LC_ALL=C
4242
# TODO: Reduce KNOWN_VIOLATIONS by replacing uses of locale dependent snprintf with strprintf.
4343
KNOWN_VIOLATIONS=(
4444
"src/bitcoin-tx.cpp.*stoul"
45-
"src/dbwrapper.cpp.*stoul"
4645
"src/dbwrapper.cpp:.*vsnprintf"
4746
"src/rest.cpp:.*strtol"
4847
"src/test/dbwrapper_tests.cpp:.*snprintf"

0 commit comments

Comments
 (0)