mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-04 10:26:02 -05:00
Add safe_hextou64()
This commit is contained in:
parent
7a02215d0d
commit
49b7a96eec
36
src/misc.c
36
src/misc.c
@ -181,6 +181,42 @@ safe_atou64(const char *str, uint64_t *val)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
safe_hextou64(const char *str, uint64_t *val)
|
||||||
|
{
|
||||||
|
char *end;
|
||||||
|
unsigned long long intval;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
intval = strtoull(str, &end, 16);
|
||||||
|
|
||||||
|
if (((errno == ERANGE) && (intval == ULLONG_MAX))
|
||||||
|
|| ((errno != 0) && (intval == 0)))
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_MISC, "Invalid integer in string (%s): %s\n", str, strerror(errno));
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end == str)
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_MISC, "No integer found in string (%s)\n", str);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intval > UINT64_MAX)
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_MISC, "Integer value too large (%s)\n", str);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*val = (uint64_t)intval;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
m_realpath(const char *pathname)
|
m_realpath(const char *pathname)
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,9 @@ safe_atoi64(const char *str, int64_t *val);
|
|||||||
int
|
int
|
||||||
safe_atou64(const char *str, uint64_t *val);
|
safe_atou64(const char *str, uint64_t *val);
|
||||||
|
|
||||||
|
int
|
||||||
|
safe_hextou64(const char *str, uint64_t *val);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
m_realpath(const char *pathname);
|
m_realpath(const char *pathname);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user