Skip to content
Snippets Groups Projects
Commit 561cd3b5 authored by Anjan Chanda's avatar Anjan Chanda
Browse files

libeasy: check for errors in strtob()

parent 29177663
Branches
Tags
1 merge request!67Devel
......@@ -41,7 +41,19 @@ static int hex2byte(const char *hex)
LIBEASY_API uint8_t *strtob(char *str, int len, uint8_t *bytes)
{
size_t i;
size_t slen;
int i;
if (!str || !bytes)
return NULL;
slen = strlen(str);
if (!slen || slen % 2 || str[slen] != '\0')
return NULL;
slen >>= 1;
if (len > slen)
len = slen;
for (i = 0; i < len; i++) {
int a;
......@@ -60,7 +72,7 @@ LIBEASY_API char *btostr(uint8_t *bytes, int len, char *str)
{
size_t i;
if (!str)
if (!str || !bytes)
return NULL;
for (i = 0; i < len; i++)
......
......@@ -16,9 +16,9 @@ extern "C" {
* "001122334455" --> {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
*
* @param[in] str hex string.
* @param[in] len string length of the hex string.
* @param[in] len length of output buffer passed to the function.
* @param[out] bytes output buffer to write the converted hex string.
* @return byte array of the converted hex string.
* @return byte array of the converted hex string, or %NULL on error.
*/
extern uint8_t *strtob(char *str, int len, uint8_t *bytes);
......@@ -31,7 +31,7 @@ extern uint8_t *strtob(char *str, int len, uint8_t *bytes);
* @param[in] bytes byte array.
* @param[in] len length of the byte array.
* @param[out] str output buffer to write the hex string.
* @return hex string.
* @return hex string or %NULL on error.
*/
extern char *btostr(uint8_t *bytes, int len, char *str);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment