summaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-11-17 03:51:04 +0100
committerdefault <nobody@localhost>2023-11-17 03:51:04 +0100
commitacf3cdcf80da7c3443e202a02d4b626c13e9e8dd (patch)
treef9498dfd051d469d9e76c4b47c5704bfc9a79e48 /xs.h
parent57ab8df0076ba8d57dce16fdd3a5e38c744e1a04 (diff)
Backport from xs.
Diffstat (limited to 'xs.h')
-rw-r--r--xs.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/xs.h b/xs.h
index 7b85dcb..c0857bc 100644
--- a/xs.h
+++ b/xs.h
@@ -1180,6 +1180,8 @@ void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size
/** hex **/
+static char xs_hex_digits[] = "0123456789abcdef";
+
xs_str *xs_hex_enc(const xs_val *data, int size)
/* returns an hexdump of data */
{
@@ -1190,8 +1192,9 @@ xs_str *xs_hex_enc(const xs_val *data, int size)
p = s = xs_realloc(NULL, _xs_blk_size(size * 2 + 1));
for (n = 0; n < size; n++) {
- snprintf(p, 3, "%02x", (unsigned char)data[n]);
- p += 2;
+ *p++ = xs_hex_digits[*data >> 4 & 0xf];
+ *p++ = xs_hex_digits[*data & 0xf];
+ data++;
}
*p = '\0';