From 58cad2995b865e114f17f00c63310c6ca0b94838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Sun, 21 Jul 2024 23:17:04 +0300 Subject: [PATCH] =?UTF-8?q?mdbx:=20=D0=B4=D0=BE-=D0=B8=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D0=B0=20`796b7e44976132944847694fc8caa5b01c0?= =?UTF-8?q?7a406`=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BB=D0=B0=D0=B4?= =?UTF-8?q?=D0=BE=D1=87=D0=BD=D1=8B=D1=85=20=D1=81=D0=B1=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/core.c b/src/core.c index 276de3ef..08a38465 100644 --- a/src/core.c +++ b/src/core.c @@ -3612,19 +3612,26 @@ __cold void debug_log(int level, const char *function, int line, va_end(args); } -/* Dump a key in ascii or hexadecimal. */ -const char *mdbx_dump_val(const MDBX_val *key, char *const buf, +/* Dump a val in ascii or hexadecimal. */ +const char *mdbx_dump_val(const MDBX_val *val, char *const buf, const size_t bufsize) { - if (!key) + if (!val) return ""; - if (!key->iov_len) + if (!val->iov_len) return ""; if (!buf || bufsize < 4) return nullptr; + if (!val->iov_base) { + int len = snprintf(buf, bufsize, "", val->iov_len); + assert(len > 0 && (size_t)len < bufsize); + (void)len; + return buf; + } + bool is_ascii = true; - const uint8_t *const data = key->iov_base; - for (size_t i = 0; i < key->iov_len; i++) + const uint8_t *const data = val->iov_base; + for (size_t i = 0; i < val->iov_len; i++) if (data[i] < ' ' || data[i] > '~') { is_ascii = false; break; @@ -3633,14 +3640,14 @@ const char *mdbx_dump_val(const MDBX_val *key, char *const buf, if (is_ascii) { int len = snprintf(buf, bufsize, "%.*s", - (key->iov_len > INT_MAX) ? INT_MAX : (int)key->iov_len, data); + (val->iov_len > INT_MAX) ? INT_MAX : (int)val->iov_len, data); assert(len > 0 && (size_t)len < bufsize); (void)len; } else { char *const detent = buf + bufsize - 2; char *ptr = buf; *ptr++ = '<'; - for (size_t i = 0; i < key->iov_len && ptr < detent; i++) { + for (size_t i = 0; i < val->iov_len && ptr < detent; i++) { const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; *ptr++ = hex[data[i] >> 4];