mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 04:34:12 +08:00
mdbx: до-исправление коммита 796b7e44976132944847694fc8caa5b01c07a406
для отладочных сборок.
This commit is contained in:
parent
37217cb199
commit
58cad2995b
23
src/core.c
23
src/core.c
@ -3612,19 +3612,26 @@ __cold void debug_log(int level, const char *function, int line,
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dump a key in ascii or hexadecimal. */
|
/* Dump a val in ascii or hexadecimal. */
|
||||||
const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
|
const char *mdbx_dump_val(const MDBX_val *val, char *const buf,
|
||||||
const size_t bufsize) {
|
const size_t bufsize) {
|
||||||
if (!key)
|
if (!val)
|
||||||
return "<null>";
|
return "<null>";
|
||||||
if (!key->iov_len)
|
if (!val->iov_len)
|
||||||
return "<empty>";
|
return "<empty>";
|
||||||
if (!buf || bufsize < 4)
|
if (!buf || bufsize < 4)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
if (!val->iov_base) {
|
||||||
|
int len = snprintf(buf, bufsize, "<nullptr.%zu>", val->iov_len);
|
||||||
|
assert(len > 0 && (size_t)len < bufsize);
|
||||||
|
(void)len;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_ascii = true;
|
bool is_ascii = true;
|
||||||
const uint8_t *const data = key->iov_base;
|
const uint8_t *const data = val->iov_base;
|
||||||
for (size_t i = 0; i < key->iov_len; i++)
|
for (size_t i = 0; i < val->iov_len; i++)
|
||||||
if (data[i] < ' ' || data[i] > '~') {
|
if (data[i] < ' ' || data[i] > '~') {
|
||||||
is_ascii = false;
|
is_ascii = false;
|
||||||
break;
|
break;
|
||||||
@ -3633,14 +3640,14 @@ const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
|
|||||||
if (is_ascii) {
|
if (is_ascii) {
|
||||||
int len =
|
int len =
|
||||||
snprintf(buf, bufsize, "%.*s",
|
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);
|
assert(len > 0 && (size_t)len < bufsize);
|
||||||
(void)len;
|
(void)len;
|
||||||
} else {
|
} else {
|
||||||
char *const detent = buf + bufsize - 2;
|
char *const detent = buf + bufsize - 2;
|
||||||
char *ptr = buf;
|
char *ptr = buf;
|
||||||
*ptr++ = '<';
|
*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',
|
const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
|
||||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
*ptr++ = hex[data[i] >> 4];
|
*ptr++ = hex[data[i] >> 4];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user