|
@@ -51,10 +51,14 @@ void base16_encode ( const uint8_t *raw, size_t len, char *encoded ) {
|
51
|
51
|
char *encoded_bytes = encoded;
|
52
|
52
|
size_t remaining = len;
|
53
|
53
|
|
|
54
|
+ /* Encode each byte */
|
54
|
55
|
for ( ; remaining-- ; encoded_bytes += 2 ) {
|
55
|
56
|
sprintf ( encoded_bytes, "%02x", *(raw_bytes++) );
|
56
|
57
|
}
|
57
|
58
|
|
|
59
|
+ /* Ensure terminating NUL exists even if length was zero */
|
|
60
|
+ *encoded_bytes = '\0';
|
|
61
|
+
|
58
|
62
|
DBG ( "Base16-encoded to \"%s\":\n", encoded );
|
59
|
63
|
DBG_HDA ( 0, raw, len );
|
60
|
64
|
assert ( strlen ( encoded ) == base16_encoded_len ( len ) );
|