fixed error return to 0, -1 lead to int overflows

This commit is contained in:
TLINDEN
2015-07-09 18:37:33 +02:00
parent 6e8dadbad9
commit da6dda795b

View File

@@ -95,7 +95,7 @@ size_t _hex2bin(const char *hex_str, unsigned char *byte_array, size_t byte_arra
if (byte_array_size > byte_array_max)
{
// Too big for the output array
return -1;
return 0;
}
if (hex_str_len % 2 == 1)
@@ -103,7 +103,7 @@ size_t _hex2bin(const char *hex_str, unsigned char *byte_array, size_t byte_arra
// hex_str is an odd length, so assume an implicit "0" prefix
if (sscanf(&(hex_str[0]), "%1hhx", &(byte_array[0])) != 1)
{
return -1;
return 0;
}
i = j = 1;
@@ -113,7 +113,7 @@ size_t _hex2bin(const char *hex_str, unsigned char *byte_array, size_t byte_arra
{
if (sscanf(&(hex_str[i]), "%2hhx", &(byte_array[j])) != 1)
{
return -1;
return 0;
}
}