diff options
author | fanquake <fanquake@gmail.com> | 2021-10-11 08:45:11 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2021-10-11 08:51:00 +0800 |
commit | 01129ca37272408d11558f0f0db41c8913da6f38 (patch) | |
tree | 390483c1230a6b8335f44c699ebe821b5c7599bd /src/dbwrapper.cpp | |
parent | d1e63aa4546989bae94111905c303ca326456330 (diff) | |
parent | fa165e954579436fe4b636e4222d8ce0c1269786 (diff) |
Merge bitcoin/bitcoin#23214: Replace stoul with ToIntegral in dbwrapper
fa165e954579436fe4b636e4222d8ce0c1269786 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 fa165e954579436fe4b636e4222d8ce0c1269786
practicalswift:
cr ACK fa165e954579436fe4b636e4222d8ce0c1269786
theStack:
Code-review ACK fa165e954579436fe4b636e4222d8ce0c1269786
Tree-SHA512: b87f01431ca0b971ff84610022da8679d3c33470b88cfc3f4a337e6e176a0455715588aefd40e8e2bbe7459d902dc89d7bfe34e7fd66755f631cc18dc039fa2f
Diffstat (limited to 'src/dbwrapper.cpp')
-rw-r--r-- | src/dbwrapper.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 3a1086bf4c..bcaf746167 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -197,13 +197,15 @@ bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync) return true; } -size_t CDBWrapper::DynamicMemoryUsage() const { +size_t CDBWrapper::DynamicMemoryUsage() const +{ std::string memory; - if (!pdb->GetProperty("leveldb.approximate-memory-usage", &memory)) { + std::optional<size_t> parsed; + if (!pdb->GetProperty("leveldb.approximate-memory-usage", &memory) || !(parsed = ToIntegral<size_t>(memory))) { LogPrint(BCLog::LEVELDB, "Failed to get approximate-memory-usage property\n"); return 0; } - return stoul(memory); + return parsed.value(); } // Prefixed with null character to avoid collisions with other keys |