From f4021c802880f2d7ecdd5eaf538cbb04ee5079b4 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Thu, 30 Jul 2020 13:41:14 +0300 Subject: [PATCH] mdbx: refine mdbx_dump_val(). Change-Id: I72dac7c44c842d16d6b8776248ba20014d0709a9 --- src/core.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core.c b/src/core.c index f5037e69..f852a4b0 100644 --- a/src/core.c +++ b/src/core.c @@ -3387,17 +3387,18 @@ const char *mdbx_dump_val(const MDBX_val *key, char *const buf, const size_t bufsize) { if (!key) return ""; - if (!buf || bufsize < 4) - return nullptr; if (!key->iov_len) return ""; + if (!buf || bufsize < 4) + return nullptr; - const uint8_t *const data = key->iov_base; bool is_ascii = true; - unsigned i; - for (i = 0; is_ascii && i < key->iov_len; i++) - if (data[i] < ' ' || data[i] > 127) + const uint8_t *const data = key->iov_base; + for (unsigned i = 0; i < key->iov_len; i++) + if (data[i] < ' ' || data[i] > '~') { is_ascii = false; + break; + } if (is_ascii) { int len = @@ -3409,7 +3410,7 @@ const char *mdbx_dump_val(const MDBX_val *key, char *const buf, char *const detent = buf + bufsize - 2; char *ptr = buf; *ptr++ = '<'; - for (i = 0; i < key->iov_len; i++) { + for (unsigned i = 0; i < key->iov_len; i++) { const ptrdiff_t left = detent - ptr; assert(left > 0); int len = snprintf(ptr, left, "%02x", data[i]);