diff --git a/src/tinyframe.c b/src/tinyframe.c index d9be679..7cfc740 100644 --- a/src/tinyframe.c +++ b/src/tinyframe.c @@ -41,7 +41,7 @@ #include static const char* printable_string(const uint8_t* data, size_t len) { - static char buf[512]; + static char buf[512], hex; size_t r = 0, w = 0; while (r < len && w < sizeof(buf) - 1) { @@ -52,8 +52,20 @@ static const char* printable_string(const uint8_t* data, size_t len) break; } - sprintf(&buf[w], "\\x%02x", data[r++]); - w += 4; + buf[w++] = '\\'; + buf[w++] = 'x'; + hex = (data[r] & 0xf0) >> 4; + if (hex > 9) { + buf[w++] = 'a' + (hex - 10); + } else { + buf[w++] = '0' + hex; + } + hex = data[r++] & 0xf; + if (hex > 9) { + buf[w++] = 'a' + (hex - 10); + } else { + buf[w++] = '0' + hex; + } } } if (w >= sizeof(buf)) {