|
@@ -15,17 +15,24 @@ int bcd2dec(int bcd) {
|
15
|
15
|
return ((bcd>>4) * 10) + bcd % 16;
|
16
|
16
|
}
|
17
|
17
|
|
18
|
|
-char *ts_hex_dump(uint8_t *d, int size, int col) {
|
|
18
|
+void ts_hex_dump_buf(char *buf, int bufsz, uint8_t *d, int size, int col) {
|
19
|
19
|
int i;
|
20
|
|
- char *buf = calloc(1, size * 6);
|
21
|
|
- if (!buf)
|
22
|
|
- return NULL;
|
|
20
|
+ if (bufsz < size * 6)
|
|
21
|
+ return;
|
|
22
|
+ memset(buf, 0, bufsz);
|
23
|
23
|
for (i=0;i<size;i++) {
|
24
|
24
|
if (col && (i % col == col - 1))
|
25
|
25
|
sprintf(buf+(i*3), "%02x\n", d[i]);
|
26
|
26
|
else
|
27
|
27
|
sprintf(buf+(i*3), "%02x ", d[i]);
|
28
|
28
|
}
|
|
29
|
+}
|
|
30
|
+
|
|
31
|
+char *ts_hex_dump(uint8_t *d, int size, int col) {
|
|
32
|
+ char *buf = malloc(size * 6);
|
|
33
|
+ if (!buf)
|
|
34
|
+ return NULL;
|
|
35
|
+ ts_hex_dump_buf(buf, size * 6, d, size, col);
|
29
|
36
|
return buf;
|
30
|
37
|
}
|
31
|
38
|
|