Fix off-by-one error in __hex2str() (#130)

This commit is contained in:
Rafał Wojdyła
2017-12-05 15:54:10 +00:00
committed by Don Porter
parent ce49dcb03d
commit 529a4ba3cb
+2 -2
View File
@@ -158,7 +158,7 @@ static inline __attribute__((always_inline))
char * __hex2str(void * hex, int size)
{
static char * ch = "0123456789abcdef";
char * str = __alloca(size * 2);
char * str = __alloca(size * 2 + 1);
for (int i = 0 ; i < size ; i++) {
unsigned char h = ((unsigned char *) hex)[i];
@@ -166,7 +166,7 @@ char * __hex2str(void * hex, int size)
str[i * 2 + 1] = ch[h % 16];
}
str[size * 2 - 1] = 0;
str[size * 2] = 0;
return str;
}