Skip to content

Commit

Permalink
Trace
Browse files Browse the repository at this point in the history
- Remove `sprintf()` usage from tracing
  • Loading branch information
jelu committed Apr 2, 2020
1 parent 45cdddc commit 242b1b2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/tinyframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <ctype.h>
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) {
Expand All @@ -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)) {
Expand Down

0 comments on commit 242b1b2

Please sign in to comment.