aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-07-01 00:08:14 -0400
committerCarl Dong <contact@carldong.me>2022-08-03 12:03:28 -0400
commit0f3a2532c38074dd9789d1c4c667db6ca46ff0ab (patch)
treee45ce50c4efda6ac38aa3dfeeb18dae4e2ecc8d0 /src/node
parent41c5201a90bbc2893333e334e8945759ef24e7dd (diff)
downloadbitcoin-0f3a2532c38074dd9789d1c4c667db6ca46ff0ab.tar.xz
validationcaches: Use size_t for sizes
...also move the 0-clamping logic to ApplyArgsManOptions, where it belongs.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/validation_cache_args.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/node/validation_cache_args.cpp b/src/node/validation_cache_args.cpp
index ed183c24fe..5ea0a8ca0a 100644
--- a/src/node/validation_cache_args.cpp
+++ b/src/node/validation_cache_args.cpp
@@ -8,6 +8,9 @@
#include <util/system.h>
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
#include <memory>
#include <optional>
@@ -17,11 +20,14 @@ namespace node {
void ApplyArgsManOptions(const ArgsManager& argsman, ValidationCacheSizes& cache_sizes)
{
if (auto max_size = argsman.GetIntArg("-maxsigcachesize")) {
- // Multiply first, divide after to avoid integer truncation
- int64_t size_each = *max_size * (1 << 20) / 2;
+ // 1. When supplied with a max_size of 0, both InitSignatureCache and
+ // InitScriptExecutionCache create the minimum possible cache (2
+ // elements). Therefore, we can use 0 as a floor here.
+ // 2. Multiply first, divide after to avoid integer truncation.
+ size_t clamped_size_each = std::max<int64_t>(*max_size, 0) * (1 << 20) / 2;
cache_sizes = {
- .signature_cache_bytes = size_each,
- .script_execution_cache_bytes = size_each,
+ .signature_cache_bytes = clamped_size_each,
+ .script_execution_cache_bytes = clamped_size_each,
};
}
}