From 26c4b673c4d8dba91211726e2101637d75b3ca0a Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 11 Aug 2018 22:06:26 +0300 Subject: [PATCH] mdbx-test: fix keylen/datalen min/max ranges checking. --- test/keygen.cc | 8 ++++---- test/main.cc | 27 ++++++++++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/test/keygen.cc b/test/keygen.cc index 99b46f29..1b18fa00 100644 --- a/test/keygen.cc +++ b/test/keygen.cc @@ -122,16 +122,16 @@ void maker::setup(const config::actor_params_pod &actor, unsigned thread_number) { key_essentials.flags = actor.table_flags & (MDBX_INTEGERKEY | MDBX_REVERSEKEY); - assert(actor.keylen_min < UINT8_MAX); + assert(actor.keylen_min <= UINT8_MAX); key_essentials.minlen = (uint8_t)actor.keylen_min; - assert(actor.keylen_max < UINT16_MAX); + assert(actor.keylen_max <= UINT16_MAX); key_essentials.maxlen = (uint16_t)actor.keylen_max; value_essentials.flags = actor.table_flags & (MDBX_INTEGERDUP | MDBX_REVERSEDUP); - assert(actor.datalen_min < UINT8_MAX); + assert(actor.datalen_min <= UINT8_MAX); value_essentials.minlen = (uint8_t)actor.datalen_min; - assert(actor.datalen_max < UINT16_MAX); + assert(actor.datalen_max <= UINT16_MAX); value_essentials.maxlen = (uint16_t)actor.datalen_max; assert(thread_number < 2); diff --git a/test/main.cc b/test/main.cc index bc3198ed..e6e0e177 100644 --- a/test/main.cc +++ b/test/main.cc @@ -188,20 +188,33 @@ int main(int argc, char *const argv[]) { config::duration, 1)) continue; if (config::parse_option(argc, argv, narg, "keylen.min", params.keylen_min, - config::no_scale, 0, params.keylen_max)) + config::no_scale, 0, UINT8_MAX)) { + if (params.keylen_max < params.keylen_min) + params.keylen_max = params.keylen_min; continue; - if (config::parse_option(argc, argv, narg, "keylen.max", params.keylen_max, - config::no_scale, params.keylen_min, - mdbx_get_maxkeysize(0))) + } + if (config::parse_option( + argc, argv, narg, "keylen.max", params.keylen_max, config::no_scale, + 0, std::min(mdbx_get_maxkeysize(0), (int)UINT16_MAX))) { + + if (params.keylen_min > params.keylen_max) + params.keylen_min = params.keylen_max; continue; + } if (config::parse_option(argc, argv, narg, "datalen.min", params.datalen_min, config::no_scale, 0, - params.datalen_max)) + UINT8_MAX)) { + if (params.datalen_max < params.datalen_min) + params.datalen_max = params.datalen_min; continue; + } if (config::parse_option(argc, argv, narg, "datalen.max", - params.datalen_max, config::no_scale, - params.datalen_min, MDBX_MAXDATASIZE)) + params.datalen_max, config::no_scale, 0, + std::min((int)UINT16_MAX, MDBX_MAXDATASIZE))) { + if (params.datalen_min > params.datalen_max) + params.datalen_min = params.datalen_max; continue; + } if (config::parse_option(argc, argv, narg, "batch.read", params.batch_read, config::no_scale, 1)) continue;